C Programming - Bitwise Operators - Discussion
Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 6)
6.
What will be the output of the program?
#include<stdio.h>
int main()
{
printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1);
return 0;
}
Discussion:
36 comments Page 2 of 4.
Jayesh said:
1 decade ago
What is GCC 32 bit platform, please explain me.
Teja said:
1 decade ago
@Anusha,
Given code is
#include<stdio.h>
int main()
{
printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1);
return 0;
}
First we got the output from 4>>1,8>>1 is 2,4 directly.
But in printf() four %d's are given.so 2,4 assigns to first two %d's and the remaining two %d's will show the garbage values.
Got it?
Given code is
#include<stdio.h>
int main()
{
printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1);
return 0;
}
First we got the output from 4>>1,8>>1 is 2,4 directly.
But in printf() four %d's are given.so 2,4 assigns to first two %d's and the remaining two %d's will show the garbage values.
Got it?
(1)
Bhagyshri said:
1 decade ago
gcc 32 is compiler in unix o.s.
Gowda said:
1 decade ago
Here is my code.
#include<stdio.h>
int main ()
{
int i ;
for (i=0;i<3;++i)
printf ("%d\n", i) ;
return 0;
}
I am getting output as 0 1 2.
Can any one explain why am not getting from 1 as I used pre-increment operator.
#include<stdio.h>
int main ()
{
int i ;
for (i=0;i<3;++i)
printf ("%d\n", i) ;
return 0;
}
I am getting output as 0 1 2.
Can any one explain why am not getting from 1 as I used pre-increment operator.
Maddy said:
1 decade ago
Please make the condition as for(i=1;i<=3;i++) , pre/post increment has no significance here.
Chinnu said:
1 decade ago
What is mean by rest is garbage. ?
Balayogi said:
1 decade ago
Post or pre increments gives the same result when they are free,like i++ and ++i(i.e.without assignment)
Kuljeet said:
1 decade ago
@Chinnu- Rest is garbage means, the other %d's in the printf fuction will print any arbitrary value.. thats known as garbage value..
Mayur said:
1 decade ago
4 = 0100 now shift to right 1 time. It will become 0010 = 2.
Then << is print on screen (becoz every special symbol or character print as well as written in double cotation " " )
Then it will print
8 = 1000 now shift to right 1 time. It will become 0100 = 4.
Then print Garbage value >> Garbage value
So,
Output will
2 >> 4 Garbage value >> Garbage value
Then << is print on screen (becoz every special symbol or character print as well as written in double cotation " " )
Then it will print
8 = 1000 now shift to right 1 time. It will become 0100 = 4.
Then print Garbage value >> Garbage value
So,
Output will
2 >> 4 Garbage value >> Garbage value
Sachin said:
1 decade ago
@Gowda.
Arrange your number in three arrays see there is no number for 3rd row, 3rd column. So it's partially initialized which has default value zero.
Arrange your number in three arrays see there is no number for 3rd row, 3rd column. So it's partially initialized which has default value zero.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers