'<<' is the bitwise left shift operator - Shifts the bits to left.
'm<<n' shifts the bits of m to the left by n times.
'>>' is the bitwise right shift operator - Shifts the bits to right.
'm>>n' shifts the bits of m to the right by n times.
Say, '2<<3': means shift bits of 2 to left 3 times
Since bit representation of 2 is 00000010
If we shift bits in 2 to left 3 times, we'll get - 00010000
Therefore, 2<<3 = 00010000 = 16
Similarly, '2>>3': means shift bits of 2 to right 3 times
2>>3 = 00000000 = 0
Associativity of bitwise left shift and right shift operators is - left to right.
The output of your program will be:
2
0
Explanation:
In the first printf, '2<<2>>'
is associated like - '((2<<2)>>2)'
Means first left shift bits in 2 by 2 and then right shift by 2, which yields 00000010, i.e 2.
In the second printf, '2>>2<<2<<(1<<1)'
is associated like - '(((2>>2)<<2)<<(1<<1))'
On evaluating this, we'll get 00000000, i.e 0.