There are two important points here:
The evaluation order of the arguments to the Unspecified function. So either:
foo() is executed first ori is printed first
It is specific to your compiler. It looks like your compiler evaluates the argument from right to left, so global i , which 0 evaluates to 0 . Remember that this order may be different for other compilers, and you should not rely on the behavior of one implementation.
How about 3 ? The destructor for ob is called after the function returns. So i gets the value 10 after return, what is returned is a copy, and this copy has a value of 3 .
source share