+ 1
Problem with compiler logic?
Simple example: int x=10, y=5; cout<<y++ + 2<<endl; cout<<x++ + x; SoloLearnC++ gives 7 and 21; Dev-C++ 4.9.9.2 gives 7 and 20; Problem how the compiler interpret x after operation x++. int x =10; x++ + x; SoloLearnC++ interpret like this: 10 + 11 = 21, x=11; DevC++ interpret: 10 + 10 = 20, x=11;
2 ответов
+ 5
"Problem with compiler logic"
Have you heard of "Undefined behavior"?!
These two expressions break the sequencing rule.
y++ + 2
x++ + x
"Modifying an object between two sequence points more than once produces undefined behavior.[...] ¹"
_____
¹ https://en.wikipedia.org/wiki/Undefined_behavior
0
So if I play one-on-one with someone, and the system gives me the tasks containing "undefined behavior" like x++ + x, I can just say: bad task. ok)