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.

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.

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.

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?

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..

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

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)

Maddy said:   1 decade ago
Please make the condition as for(i=1;i<=3;i++) , pre/post increment has no significance here.

Anushka said:   9 years ago
But in the right shift. Spaces are filled with 1. Then how 0010 can occur?

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?


Post your comments here:

Your comments will be displayed after verification.