Your code is undefined behavior, so there is no such thing as “correct logic” for it — it could output 0 0 0
, 1 1 2
, hello, world
, or emit nasal demons.
From C99 standard:
-
Section 6.5, paragraph 2:
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 read only to determine the value to be stored.
-
Section 6.5.2.2, paragraph 10:
The order of evaluation of the function designator, the actual arguments, and subexpressions within the actual arguments is unspecified, but there is a sequence point before the actual call.
5
solved What is the output of the a,a++,++a when a=1; [duplicate]