No prob!
Vig.
Printable View
No prob!
Vig.
Viggy had it right.
Operator precedence would evaluate the ++x first, so x = 5 after this is done. Then x + x = 10
It is only one possibility.Quote:
Originally Posted by INeedHelp2
There are plenty others:
- compile-time error.
- crash
- It is very probable that it may yield any value in range [7, 10]
And, saying simply that "side effects appear in any order" is not exact.
Side effects can appear in any order and may even be interlaced!
For example, if there were a primitive operator "swap bytes" (little endian <-> big endian), doing something like:
Would probably make some bytes appear twice, and others not at all, and in any order...Code:swapbytes(swapbytes(x))
Indeed any program that make two side effects on the same lvalue between two sequence points, has undefined behaviour.
It may play the 9th symphony of Beethoven...