Does it have something to do with order of execution of cout statement?
Code:
int main() {
int x=80;
int &y=x;
cout<<x<<" "<<(--y)<<endl;
return 0;
}
Output: 79 79
Does it have something to do with order of execution of cout statement?
Code:
int main() {
int x=80;
int &y=x;
cout<<x<<" "<<(--y)<<endl;
return 0;
}
Output: 79 79
Does it have something to do with order of execution of cout statement?
This has everything to do with the order of evaluation. Until c++17 your example would exhibit undefined behaviour:
If a side effect on a scalar object is unsequenced relative to a value computation using the value of the same scalar object, the behavior is undefined.
Since c++17 the behaviour is defined and the correct output in this case is
80 79
It's undefined behavior, meaning anything could happen.
For more information see: Unexpected order of evaluation (compiler bug?)