What is the output of the following C++ code?
int x=7;
int y=5;
cout << (x ^ y);
Options
- A. 2
- B. 3
- C. 1
- D. More than one of the above
- E. None of the above
Quiz Practice:
int x=7;
int y=5;
cout << (x ^ y);
A. 2
Answer: (A) 2
The ^ operator performs a bitwise XOR operation.
7 = 0111
5 = 0101
In XOR, the result is 1 when the two corresponding bits are different.
0111
0101
----
0010
0010 is 2 in decimal.