Increment Operator (++)

The expression ++n evaluates to the value n + 1, and the expression n++ evaluates to n.
In both cases, immediately after the evaluation occurs, a side-effect increments n.

Within a larger expression, after each sub-expression is evaluated, the resulting side-effect occurs before the next sub-expression is evaluated.

For example:

                int a = 1;
                int b = ++a + a++ + ++a + a++;  // a == 5, b == 12

 

                          2 + 2   +   4 + 4 evaluates to:
                          2   3       4   5 then, a equals:

Copyright © 2003 The Stevens Computing Services Company, Inc.  All rights reserved.