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 1 of 4.
Neetu said:
1 decade ago
4 = 0100 now shift to right 1 time. It will become 0010 = 2.
8 = 1000 now shift to right 1 time. It will become 0100 = 4.
Rest is garbage, so the answer is C.
8 = 1000 now shift to right 1 time. It will become 0100 = 4.
Rest is garbage, so the answer is C.
Sundar said:
1 decade ago
I got the following outputs:
In GCC (32-bit platform): 2 >> 4 134513662 >> 134513904
Turbo c (16 bit platorm): 2 >> 4 0 >> 344
Therefore, 2 >> 4 garbagevalue >> garbagevalue is the correct answer.
In GCC (32-bit platform): 2 >> 4 134513662 >> 134513904
Turbo c (16 bit platorm): 2 >> 4 0 >> 344
Therefore, 2 >> 4 garbagevalue >> garbagevalue is the correct answer.
Divya s said:
1 decade ago
Yes neetu understood thanks
Maruti shrivastava said:
1 decade ago
Very thanks to you neetu.
Mukesh said:
1 decade ago
2 >> 4 rest depends on the compiler..
Deepika said:
1 decade ago
Thanks Neetu.....
Maya said:
1 decade ago
Why shouLd we right shift to one place?
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 >>.
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
Anusha said:
1 decade ago
Why do we get garbage values can you explain?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers