C++ xor_eq Keyword
Example
The xor_eq keyword gives the same result as the ^= operator:
int x = 5;
int y = 5;
x ^= 3;
y xor_eq 3;
cout << x << "\n";
cout << y;
Definition and Usage
The xor_eq keyword is another way to write the ^= assignment operator. y xor_eq 3 is the same as y = y ^ 3. Both ways work the same, but ^= is much more common.
The ^ operator (exclusive or) compares the bits (the 1s and 0s that a number is stored as) of two numbers. Each bit in the result is 1 if the two bits are different, and 0 if they are the same. For example, 5 is 101 in binary and 3 is 011, so 5 ^ 3 is 110, which is 6.
Related Pages
Read more about assignment operators in our C++ Assignment Operators Tutorial.