For this particular result, g() + f()
is being evaluated first which will result in a
eventually being incremented to 10
and the result being 18
. This is the case regardless of whether the g()
or f()
bit of that sum is done first. Doing g()
first gives 8+10
, otherwise it's 9+9
.
Then f()
is evaluated, setting a
to 11
and returning 11
.
Then g()
is evaluated, setting a
to 12
and returning 11
.
In other words, it's calling the right-most bits of the cout
first and proceeding left.
Now you'll notice the phrase "for this particular result" in my ramblings above. Whether this is mandated by the standard, I don't know for sure (meaning I couldn't be bothered looking it up at the moment), but I very much doubt it, based on experience.
So, while it's actually outputting the items in the correct order, the side effects can be different depending on a large number of things. That's one reason why global variables (or, more correctly, side effects on them) are rarely a good idea and you should probably rethink your use of them :-)