How shall the compiler know which part has to be calculated first (b=(a=b+0.5)
or (c=b)? Shouldn't the succession of these two expressions be undefined?
#include <iostream>
int main()
{
double a = 8, b = 9, c = 7;
std::cout << (b = (a = b + 0.5) + (c = b)) << std::endl;
std::cout << "a = " << a << " b = " << b << " c = " << c << std::endl;
std::cout << a / 2 << " " << b / 2 << " " << c / 2 << std::endl;
}
Starting with (b = (a = b + 0.5) + (c = b)) what you will end up with is (b = (a = 9 + 0.5) + (c = b)) --> (b = (9.5) + (c = 9)) -->(b = 9.5 + 9) --> prints b which = 18.5. After the first line is printed a = 9.5, b = 18.5 and c = 9. c = 9 because b was used before it changed.
The second cout will show what each variable is after the first cout.