前缀增量和减量运算符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. 操作数必须具有整型、浮点型或指针类型且必须是可修改的左值表达式(不带 const 特性的表达式)。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.

整型或浮动类型的操作数将按整数值 1 递增或递减。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;  

在此示例中,变量 i 在用作 line 的下标之前是递减的。In this example, the variable i is decremented before it is used as a subscript to line.

另请参阅See Also

C 一元运算符C Unary Operators