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.
Anushka said:
9 years ago
But in the right shift. Spaces are filled with 1. Then how 0010 can occur?
Praba said:
9 years ago
What is mean by rest is garbage?
Krutika said:
9 years ago
Thank you @Mayur.
Prat said:
9 years ago
Why garbage value? Please explain clearly.
Adam said:
9 years ago
#include<stdio.h>
int main()
{
printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1);
printf("%d >> %d >> \n", 4 >> 1, 8 >> 1);
printf("%d %d \n", 4 >> 1, 8 >> 1);
return 0;
}
Try this.
int main()
{
printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1);
printf("%d >> %d >> \n", 4 >> 1, 8 >> 1);
printf("%d %d \n", 4 >> 1, 8 >> 1);
return 0;
}
Try this.
Jay said:
1 decade ago
First it solve 4>>1 and then solve 8>>1.
Answer is 2 and 4.
Then it print the value.
But here %d is 4 times in printf("").
So it print only two values and other two are garbage value.
Answer is 2 and 4.
Then it print the value.
But here %d is 4 times in printf("").
So it print only two values and other two are 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.
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
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..
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)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers