There is no right or wrong output. Your code has undefined behavior and anything is possible.
The reason lies in paragraph 1.9.15 (n3337) of C++ standard (emphasis mine):
Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced. [Note: In an expression that is evaluated more than once during the execution of a program, unsequenced and indeterminately sequenced evaluations of its subexpressions need not be performed consistently in different evaluations. —end note ] The value computations of the operands of an operator are sequenced before the value computation of the result of the operator. If a side effect on a scalar object is unsequenced relative to either another side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined.
In this line
cout << y-- << "," << --y;
you've introduced two side effects (increments by postfix and prefix, respectively) and two value computations (results of y--
and --y
) on a scalar object (y
) where they are unsequenced. Thus, your program is ill-formed and just about anything is a possible output.
Read more about this here.