TOPIC 5.1.2
Compound
Operators
The following operators are bitwise compound operators and are similar to the arighmetic assignment operators.
Operator Function Example &= (Bitwise AND) x &= 8 |= (Bitwise OR) x |= 1 ^= (Bitwise XOR) x ^= 4 >>= (Bitwise shift right) x >>= 4 <<= (Bitwise shift left) x <<= 3
These operators work the same as the bitwise operators discussed in 7.1.2 Bitwise Operators, with the shorthand notation of compound operators. The only drawback, as with the other compound operators, is that the compound operators have lowest precedence in the order of operations. Which as you might have already found out, may causes bugs that are hard to detect. The only way to be able to find these bugs is by practice and example. The following practices should help you feel more comfortable using compound operators.
int x, y = 10, z = 5; x += 100 * z
x = 10; x += z * 10;
x = 10; x *= 10 * x;
x = 10; x /= x;
x = 2; x /= x--;