What does ^ operator do in c++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What does ^ operator do in c++?

and if any library should we include to use this operator?

1st Apr 2017, 1:04 PM
suyash ajmera
suyash ajmera - avatar
4 Answers
+ 4
@WINTER ^ is the XOR operator in C++, just like @Dennis explained. It calculates powers only in a calculator. But, if you want to use it to calculate powers, you must overload it...
1st Apr 2017, 1:36 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
It's the bitwise exclusive operator, or XOR. Bits that are the same become 0, bits that are not the same become 1 15 = 1111 6 = 110 _________ 9 = 1001
1st Apr 2017, 5:29 PM
Dennis
Dennis - avatar
+ 1
is any shortcut technique to do that like other bitwise operators have
1st Apr 2017, 1:25 PM
suyash ajmera
suyash ajmera - avatar
+ 1
cout << ( 15 ^ 6 ) << endl; //XOR, 9 cout << ( 15 | 6 ) << endl; //Or, 15 cout << ( 15 & 6 ) << endl; //And, 6
1st Apr 2017, 1:31 PM
Dennis
Dennis - avatar