next up previous contents
Next: 5.8 Precedence and Order Up: 5 Data TypesOperations, Previous: 5.6 Assignment Operators and

5.7 Increment and Decrement Operators

The increment operator `` ++'' increments the named variable. For example, the statement `` a++'' is equivalent to `` a= a+1'' or `` a+= 1''.

A statement that uses an increment operator has a value. For example, the statement

    a= 3;
    printf("a=%d a+1=%d\n", a, ++a);

will display the text `` a=3 a+1=4.''

If the increment operator comes after the named variable, then the value of the statement is calculated after the increment occurs. So the statement

    a= 3;
    printf("a=%d a+1=%d\n", a, a++);

would display `` a=3 a+1=3'' but would finish with a set to 4.

The decrement operator `` --'' is used in the same fashion as the increment operator.

Fred G. Martin
Fri Mar 29 17:44:15 EST 1996