As we have already seen, expressions can be combined in many ways to form compound expressions. There are some compound expressions that recur so often that C has a set of operators that make them shorter. In each case, the result is formed by taking the variable on the left of the operator, performing the operation on it with the value of the expression on the right, and assigning it back to the variable on the left.
Compound operations are of the form variable operator= expression.
The most common of these is incrementation with an assignment:
counter = counter + 1;
With the += compound operator, this just becomes the following:
counter += 1 ;
The full set of compound operators is as follows:
- += assignment with addition to a variable
- -= assignment with subtraction to a variable
- *= assignment with multiplication to a variable
- /= assignment with division...