+ 2
Help me explain b= a-- + --a and b= --a + a--
Hi guys, can you explain that cases for me? 1. int main() { int a= -5; int c = --a + a--; cout<<a; } // I dont understand why the answer is c = -13. I think it must be c = -12. 2. int main() { int a= -5; int c = a-- + --a; cout<<a; } //The answer is c = -12. I don't understand! Please help me.
8 RĂ©ponses
+ 2
Are you sure that the last row in both examples Is "cout << a" not "cout << c"?
If it "cout << c" than the first example:
(-5-1) + (-6) = -12 --> Also don't know why -13 but I think that you have mistyped example or just I don't know...
And second:
(-5) + (-6-1) = -12
+ 10
The behaviour of programs with multiple prefix/postfix operators between two sequence points is undefined.
https://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points
+ 2
https://www.sololearn.com/discuss/523078/?ref=app
+ 1
@hatsy is right answer completly depends on compiler
+ 1
@Ondrej Donek : Thank you. I have mistyped. It is " cout<<c; ". Sorry I can't write your name exactly!
+ 1
@Minh - No problem with name - our Czech language is strange but beautiful! :) Have a nice day.
0
Thank everyone.