Cold Help System: Programming: ColdC Reference Manual: Language Structure: Expressions: Operators: Arithmetic Operators: Increment


The unary Increment (++) and Decrement (--) operators perform a dual purpose. They either add or subtract one from a numeric variable (respectively), assigning the result back to the variable. They must be used directly on a variable. All of the following are equivalent:

i = i + 1
i++
i = i - 1
i--

The result returned from an increment or decrement expression will will depend upon what side of the variable it is placed. If the operator is on the left side of the variable, the value of the variable is modified before it is returned. If the operator is on the right side of the variable, the value of the variable is returned first and then the variable is incremented or decremented.

In the examples below assume i is 10. Assuming this, in the first example x is assigned the value 10 where in the second example it is assigned the value 11.

x = i++
x=++i


Increment | Non-Numeric Use


the Cold Dark