Skip to main content

Microcontrollers

Section 14.7 Compound Operators

Compound operators combine an arithmetic or bitwise operation with an assignment operation. These are all unary operations in that they take a single operand. Compound operators are not mandatory to use as all compound operations can otherwise be accomplished by setting a variable equal to the operation taking place with that same variable. (As an example, a variable a could be incremented with a compound operation a++ or with an assignment and arithmetic operation a = a + 1.) Compound operators can save execution time in that using assignment and arithmetic/bitwise operations may require the variable to be looked up twice if the compiler does not recognize that the two parts of the expression are identical.
Compound operators are described in Tableย 14.7.1.
Table 14.7.1. Compound operators.
Operator Description
++ Increment
-- Decrement
+= Compound addition
-= Compound subtraction
*= Compound multiplication
/= Compound division
%= Compound modulo
&= Compound bitwise AND
|= Compound bitwise OR
^= Compound bitwise XOR
>>= Compound bitshift right
<<= Compound bitshift left