C++ or_eq Keyword
Example
The or_eq keyword gives the same result as the |= operator:
int x = 5;
int y = 5;
x |= 3;
y or_eq 3;
cout << x << "\n";
cout << y;
Definition and Usage
The or_eq keyword is another way to write the |= assignment operator. y or_eq 3 is the same as y = y | 3. Both ways work the same, but |= is much more common.
The | operator (bitwise 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 at least one of the two bits is 1. For example, 5 is 101 in binary and 3 is 011, so 5 | 3 is 111, which is 7.
Related Pages
Read more about assignment operators in our C++ Assignment Operators Tutorial.