++

Syntax ++identifier

identifier++

Action The increment operator adds the numeric value 1 to the value of identifier. In the first case, where the increment operator appears before identifier, the value of the increment expression is the value of identifier after it is incremented. That is, the

increment operation takes place first, and the result is used as the value of the expression. In the second case, where the increment operator appears after identifier, the value of the increment expression is the value of identifier before it is

incremented; the increment operation takes place after the expression's value has been determined.

Examples x = 3; ++x

   » 4

Since x is "pre-incremented," its final value of 4 is the result of the expression.

x = 3; x++

   » 3

In this case, x is "post-incremented," and the result of the expression is its value before 1 is added to it. Its value after the statement is executed is still 4.

Notes Any type that supports addition can be used with the increment operator.

See Also +

--

Discuss