+ 2
why out put = 1
#include <iostream> using namespace std; int main() { int a=2; int b=3; int c=a^b; cout << c << endl ; return 0; }
1 Answer
+ 6
^ is a bit-wise xor operator which return 1 when corresponding bits in two operand are different
0 ^ 0 = 0
1 ^ 1 = 0
0 ^ 1 = 1
1 ^ 0 = 1
2 = 0010
3 = 0011
Now 2 ^ 3 = 0 0 1 0
0 0 1 1
---------
0 0 0 1
Hope that helps