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

Bhagyshri said:   1 decade ago
gcc 32 is compiler in unix o.s.

Gowda said:   1 decade ago
Here is my code.

#include<stdio.h>

int main ()
{
int i ;
for (i=0;i<3;++i)
printf ("%d\n", i) ;
return 0;
}

I am getting output as 0 1 2.

Can any one explain why am not getting from 1 as I used pre-increment operator.

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

Chinnu said:   1 decade ago
What is mean by rest is garbage. ?

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)

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


Post your comments here:

Your comments will be displayed after verification.