Prefix Increment and Decrement Operators

The unary operators (++ and ––) are called "prefix" increment or decrement operators when the increment or decrement operators appear before the operand. Postfix increment and decrement has higher precedence than prefix increment and decrement. The operand must have integral, floating, or pointer type and must be a modifiable l-value expression (an expression without the const attribute). The result is an l-value.

When the operator appears before its operand, the operand is incremented or decremented and its new value is the result of the expression.

An operand of integral or floating type is incremented or decremented by the integer value 1. The type of the result is the same as the operand type. An operand of pointer type is incremented or decremented by the size of the object it addresses. An incremented pointer points to the next object; a decremented pointer points to the previous object.

Example

This example illustrates the unary prefix decrement operator:

if( line[--i] != '\n' )
    return;

In this example, the variable i is decremented before it is used as a subscript to line.

See Also

Reference

C Unary Operators