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 3 of 4.
Chinnu said:
1 decade ago
What is mean by rest is garbage. ?
Maddy said:
1 decade ago
Please make the condition as for(i=1;i<=3;i++) , pre/post increment has no significance here.
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.
Bhagyshri said:
1 decade ago
gcc 32 is compiler in unix o.s.
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)
Jayesh said:
1 decade ago
What is GCC 32 bit platform, please explain me.
Anusha said:
1 decade ago
Why do we get garbage values can you explain?
Nizamuddin said:
1 decade ago
void main()
{
int x[2][2][2]={1,2,3,4,5,6,7,8}
int *p;
p=&x[2][2][2];
printf("%d",*p);
}
ans is 0 (zero) why
{
int x[2][2][2]={1,2,3,4,5,6,7,8}
int *p;
p=&x[2][2][2];
printf("%d",*p);
}
ans is 0 (zero) why
Reenu said:
1 decade ago
@maya.
As the number gave after >> is 1..we have right shift one place..If that number is 2(>> 2)then we have to right shift 2 place..It depends on the number given after >>.
As the number gave after >> is 1..we have right shift one place..If that number is 2(>> 2)then we have to right shift 2 place..It depends on the number given after >>.
Maya said:
1 decade ago
Why shouLd we right shift to one place?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers