This is the C++ code:
#include<iostream>
using namespace std;
int a=8;
int fun(int &a)
{
a=a*a;
return a;
}
int main()
{
cout << a << endl \
<< fun(a) << endl \
<< a << endl;
return 0;
}
why does it output:
64 64 8
the << operator’s associativity is left to right, so why not output 8 64 64?
Does it have the relation to the sequence point and the effect side?
Associativity and evaluation order are not the same thing. The expression
a << b << cis equivalent to(a << b) << cdue to left-to-right associativity, but when it comes to evaluation order, the compiler is free to evaluatecfirst thena << band, likewise, it can evaluatebbefore it evaluatesa. In fact, it can even evaluate the terms in the orderb→c→aif it wants, and it just might if it concludes that such an order will maximise performance by minimising pipeline stalls, cache misses, etc.