This is a question from kn king\'s c programming : a modern approach. I can\'t understand the solution given by him:-
The expression ++i is equivalent to (i
The solution means to say that there is no difference, ++i
has the same meaning as (i += 1)
no matter what i
happens to be and no matter the context of the expression. The parentheses around i += 1
make sure that the equivalence holds even when the context contains further arithmetics, such as ++i * 3
being equivalent to (i += 1) * 3
, but not to i += 1 * 3
(which is equivalent to i += 3
).
The same would not apply to i++
, which has the same side effect (incrementing i
), but a different value in the surrounding expression — the value of i
before being incremented.