The Standard states that
Between the previous and next sequence point an object shall have its
stored value modified at most once by the evaluation of an expression.
Furthermore, the prior value shall be accessed only to determine the
value to be stored.
And these are the places where you will find sequence points:
at the end of the evaluation of a full expression (a full expression
is an expression statement, or any other expression which is not a
subexpression within any larger expression);
at the ||
, &&
, ?:
and comma operators; and
- at a function call (after the evaluation of all the arguments, and
just before the actual call).
An elaboration of the last point: the comma operators in a function call are not sequence points and the expressions between the ,
s can be evaluated in any arbitrary order.
Check this and this for better understanding.
In printf("%d %d %d %d %d \n", i, i++, i++, i++, i);
, you are writing to the same memory location more than once between two sequence points, thus invoking undefined behaviour.