0
training in this game
can you tell me in which worl isn't this five? int a=3; int b=2; b=a++; cout << b++;
6 Answers
+ 2
its answer is 4
+ 1
but the compiler read the code from right to left so it increment b and then print it
0
Basically you ignore the b=2. b=a++ is 4, the b++ is done after it prints to the screen. so the answer wouldn't be 5 unless you called b again
0
okay. I'm going to try to explain this because it took me a LOT of effort to figure this out, and I want to clear this up
so, you have this code, I won't bother explaining the first part, I assume the pre/post increments are what is confusing:
b=a++
the ++ doesn't matter, because when you put the '++' after the identifier, it uses the value of a, then changes it. So b will equal a, then it adds 1 to a.
also, then you have (assuming you meant b++, not ++b):
cout << b++
the postfix with the ++ after means that it outputs the value of b, THEN increments.
in reality, the answer should be 3 if you followed me on this.
I hope this clears up any questions you may still have.
0
i just rewrite the training from this game without include namespace etc
0
What value did it return, instead of 5 as you predicted?