Multiple choice

What is the output of the given program?

int main()
{
 printf(%d,128<<4<<3<<2>>6);
// Line 1
}

  1. 65536

  2. 1024

  3. 0

  4. 512

  5. Error at line 1

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Two kinds of operators are used in the statement: left shift (<<) and right shift (>>). The general formula to solve (N << s)  is: N * 2^s, and the general formula to solve (N >> s) is: N/2^s. So, firstly 128<<4<<3<<2 will be solved which will return 128 * (2^4) * (2^3) * (2^2) = 65536. Now the statement becomes 65536 >> 6. So, it will return 65536/2^6 = 1024. The output will be 1024. So, this is the correct answer.