Because postfix operators have higher precedence than prefix operators, so the expression ++i++
is equivalent to ++(i++)
, that is equivalent to ++( i + 1)
. The compiler gives l-value error because you are applying ++
on an expression (i++)
that is not a modifiable lvalue, so not a valid expression in c according to increment operator definition.
According to Dennis M. Ritchie's book: "The C Programming Language":
2.8 Increment and Decrement Operators
(page 44)
The increment and decrement operators can only be applied to variables; an expression like (i + j)++
is illegal. The operand must be a modifiable lvalue
of arithmetic or pointer type.
Related: An interesting bug one may like to know about in gcc 4.4.5 is that expression j = ++(i | i);
compiles that should produce l-value error. Read: j = ++(i | i); and j = ++(i & i); should an error: lvalue?
Additionally, modifying same variable more then once in an expression without an intervening sequence point causes which is undefined behavior in c and c++. To understand read Explain these undefined behaviors in i = i++ + ++i;.