Function evaluation order is not defined in C ++. In code:
cout << g() << " " << f() << " " << g() + f() << endl;
The compiler can emit code to call f (), f (), g (), g (), and then add the results. Or it can do something else.
This has nothing to do with using cout, BTW - if you write code like this:
x = a() + b() * c();
There is no guarantee what calls will cause a, b and c. This is one of the many reasons global variables are A Bad Thing - you often cannot predict how functions that change them will be called.
source
share