Increment and Decrement Operators
There are two versions of these operators, prefix and postfix. As the name suggests, prefix means that the operator is placed on the left of the operand (for example, ++i), and a postfix operator is placed to the right (i++). The ++ operator will increment the operand and the -- operator will decrement it. The prefix operator means "return the value after the operation," and the postfix operator means "return the value before the operation." So the following code will increment one variable and use it to assign another:
a = ++b;
Here, the prefix operator is used so the variable b is incremented and the variable a is assigned to the value after b has been incremented. Another way of expressing this is:
a = (b = b + 1);
The following code assigns a value using the postfix operator:
a = b++;
This means that the variable b is incremented, but the variable a is assigned to the value before b has been incremented. Another way of expressing this is:
int t;
a = (t = b, b = b + 1, t);
Note that this statement uses the comma operator, so a is assigned to the temporary variable t in the right-most expression.
The increment and decrement operators can be applied to both integer and floating point numbers. The operators can also be applied to pointers, where they have a special meaning. When you increment a pointer variable it means increment the pointer by the size of the type pointed to by the operator.