Both versions of ++
require lvalues as arguments, but the prefix version returns the value of lvalue as an argument, while the postfix version returns rvalue.
In any case, you cannot double-change the same object between points in a sequence, so your “working” example invokes undefind behavior. The output can be anything that the compiler does. If you just ask out of curiosity that it is good, but if it has to do with your actual code, you may do something wrong.
Chris lutz
source share