+ 1

How to decipher this? / Как это расшифровать?

x-=-(++x)-x I thought this is correct: x=x--(++x)-x //x=1--(2)-1=1+2-1=2 But if х=1 then answer is 5. Why is it so?

21st Oct 2018, 8:03 PM
Tobi Uchiha
Tobi Uchiha - avatar
3 ответов
+ 3
The compiler can pick any reasonable order to execute so: x=3; x=x++; x could be either 3 or 4 depending on which assignment wins. You can't know for sure because, even if it is 4 today, tomorrow it could be 3 as the compiler got modified. x=1; x=x--+++x; x could be 0 to 4 depending on which order the x assignment happen. These statement are guanteed to be undefined behavor so should never be coded.
22nd Oct 2018, 4:54 AM
John Wells
John Wells - avatar