JuniorCodeOccasionalNot answered yet
What does i = i++ + ++i; print?
Predict the output of this program — or explain why you cannot.
int i = 1;
i = i++ + ++i;
std::cout << i;
Determine the output and explain.
Undefined behavior: i is modified twice (i++ and ++i) and read with no sequence point separating the side effects, so the standard imposes no result — different compilers print different values and the program is invalid.
- ✗Computing one 'correct' value as if the operations were ordered left to right
- ✗Calling it unspecified (one of several valid outputs) rather than undefined (an invalid program)
- ✗Assuming a newer standard defines the result
- →What is the difference between unspecified behavior and undefined behavior?
- →Which C++17 expressions did gain a guaranteed evaluation order?