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 4 of 4.
Ashwini said:
8 years ago
Please explain, why garbage value occur?
Vandana said:
8 years ago
Thank you for all the given explanation.
Malu said:
7 years ago
@Neetu.
Why we should consider the rest value as garbage I can take it directly as 2 4 why should go for garbage value. Could you please explain me?
Why we should consider the rest value as garbage I can take it directly as 2 4 why should go for garbage value. Could you please explain me?
Harshal said:
7 years ago
Thanks for explaining the answer.
Sai said:
6 years ago
4>>1 means divide 4 by 2 power 1 and 8>>1 means divide 8 by 2 power 1 then you will get answer as 2 and 4 if it is less then less then multiply by 2.
(2)
Rather said:
6 years ago
Hello All.
For people who thinks why garbage values get printed , let us look at this ststement
printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1);
We have four %d's, means we should have four variables to print but here we have only two representing first two :ie 4>>1 & 8>>1, last two format specifiers have no variables listed to print , so in such cases, it will print them as garbage values.
For people who thinks why garbage values get printed , let us look at this ststement
printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1);
We have four %d's, means we should have four variables to print but here we have only two representing first two :ie 4>>1 & 8>>1, last two format specifiers have no variables listed to print , so in such cases, it will print them as garbage values.
(3)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers