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

int x=12;
int y=10;
cout << (x & y);
                        

Options

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

Correct Answer (Detailed Explanation is Below)

A. 2

Detailed Explanation

Answer: (A) 8

The & operator performs a bitwise AND operation.

12 = 1100
10 = 1010

Comparing each bit:

1100
1010
----
1000

1000 in decimal is 8.

Therefore, the output is 8.