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;
}
4 1 8 1
4 >> 1 8 >> 1
2 >> 4 Garbage value >> Garbage value
2 4
Answer: Option
Explanation:
No answer description is available. Let's discuss.
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?

Suyog said:   9 years ago
Can anybody explain about garbage?

Saikumar said:   9 years ago
Thank you @Neetu and @Teja.

Vishu said:   9 years ago
@Nizamuddin,
Array always represents starting from '0' position so there is two matrices represented as a a[0] & a[1].
so there is no a[2] so it shows a value as '0'.

If I made any mistake correct me. Thank you.

Shree said:   8 years ago
Thanks @Neetu.

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?

Harshal said:   7 years ago
Thanks for explaining the answer.

Anusha said:   1 decade ago
Why do we get garbage values can you explain?


Post your comments here:

Your comments will be displayed after verification.