next up previous
Next: Expressions with side-effect and Up: Unit 04 Previous: Combined assignment operators

Increment and decrement operators

To increment by 1 the value of an integer variable x, we can use any of the following three statements, which are all equivalent:

x = x + 1;
x += 1;
x++;
Note that the most compact form is the one using the post-increment operator ++.

Similarly, to decrement by 1 an integer variable, we can use any of the following three statements, which are all equivalent:

x = x - 1;
x -= 1;
x--;
Also in this case, the most concise form is the one that uses the post-decrement operator --.


next up previous
Next: Expressions with side-effect and Up: Unit 04 Previous: Combined assignment operators