C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 10)
10.
What will be the output of the program?
#include<stdio.h>

int main()
{
    printf("%d %d\n", 32<<1, 32<<0);
    printf("%d %d\n", 32<<-1, 32<<-0);
    printf("%d %d\n", 32>>1, 32>>0);
    printf("%d %d\n", 32>>-1, 32>>-0);
    return 0;
}
Garbage values
64 32
0 32
16 32
0 32
All zeros
8 0
0 0
32 0
0 16
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
42 comments Page 5 of 5.

Udit said:   6 years ago
Please explain the following in the code.
1. 32>>-0
2. 32<<-0

NJ Nath said:   6 years ago
32>>-1 and 32<<-1 are compiler dependent questions, in gcc compiler both values are showing as 16 and 62 respectively.


Post your comments here:

Your comments will be displayed after verification.