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:

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.