This happens because, in case of i++
, the increment takes place as a side effect after the value computation for the expression i++ <10
. Then, the loop body is executed and incremented value is printed inside the loop body.
Quoting C11
, chapter §6.5.2.4,
The result of the postfix ++
operator is the value of the operand. As a side effect, the
value of the operand object is incremented (that is, the value 1 of the appropriate type is
added to it). [...] The value computation of the result is sequenced before the side effect of
updating the stored value of the operand. [...]
and, for better understanding, quoting chapter §6.8.5.3, the for
loop
The statement
for ( clause-1 ; expression-2 ; expression-3 ) statement
behaves as follows: The expression expression-2 is the controlling expression that is
evaluated before each execution of the loop body. [....]