What will be the output of the following C++ code?

int x=16;
cout << (x >> 2);
                        

Options

  • A. 2
  • B. 4
  • C. 8
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. 4

Detailed Explanation

Answer: (B) 4

The >> operator performs a right shift.

16 in binary is 10000.

Shifting two positions to the right gives:

10000 >> 2 = 00100

The binary value 00100 is 4.

For a positive integer, a right shift by two positions commonly corresponds to integer division by 4.