When order does not matter
There is one tiny thing we ought not to forget to mention before closing this chapter. Well, actually two. The first one is that in C++, the order in which function arguments are evaluated is unspecified. This means that when you call a function with multiple arguments, the compiler is free to evaluate the arguments in any order it chooses. This can lead to unexpected results if the arguments have side effects, such as modifying a variable.
Let’s take, for example, the following program:
#include <iostream> int f (int a, int b, int c) { std::cout << "a="<<a<<" b="<<b<<" c="<<c<<std::endl; return a+b+c; } int main() { int i = 1; std::cout<<"f="<<f(i++, i++, i++)<<std::endl<<"i="<<i<<std::endl; }
Regardless of what you...