In your code, see the following step-through.
j=3; //Line 1, j ==3
i=6; //Line 2, i == 6
i+=5; //Line 3, i == i + 5 == 11
j=i--; // line 4, j == 11, i == 10, after this line.
To elaborate, the x += y
can be broken down as x = x + y
, so that's it.
and regarding the post-decrement, the side-effect (decrement) will take place after the expression is evaluated. So, anyway, before the next statement, the value of i
will get decremented.
To add some reference, from 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).[....]
and
The postfix --
operator is analogous to the postfix ++
operator, except that the value of
the operand is decremented (that is, the value 1 of the appropriate type is subtracted from
it).
Note, a difference of a pre-decrement and post-decrement is visible only within the expression they are used. From the perspective of the next instruction using the variable, they both will give you the same result (effect).