Why this snippet:
int i = 0;
cout << ++i << " " << ++i;
produces 2 2
instead of 1 2
?
EDIT: Pointers to answers about undefined evaluation order don't clear this issue for me. If cout << ++i << " " << ++i
is translated to f (++i, " ", ++i)
there seem to be only 2 relevant cases:
- 1st parameter is evaluated before 3rd one:
f (0, " ", 1)
- 3rd parameter is evaluated before 1st one:
f (1, " ", 0)
Where is 2 2
coming from?
EDIT: OK, I get it: "Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression".