引用 ISO C99 标准:
6.5.2.4 Postfix increment and decrement operators
Constraints
1
The operand of the postfix increment or decrement operator shall have qualified or
unqualified real or pointer type and shall be a modifiable lvalue.
对于这种情况:
++*p++; //Statement 2
后缀++具有更高的优先级和前缀++,*具有相同的优先级和right to left关联性。这意味着在第一步它增加指针而不是它的值。所以它会给你那个的下一个地址type。然后value (which is actually *p)递增。所以,在这种情况下没有 constraint violation。它与 相同++(*(p++))。
对于以下其他情况:
int x=10;
++x++; //Statement 1
在上述变量(不是指针)的情况下++(后缀或前缀增量或减量)给你rvalue, 然后应用++或--on rvalueis constraint violation。++或--操作数应该是一个lvalue. 请参阅上面写的标准报价。因此给出错误。