0

Why when i set b to 1, 5 or 10 the answer is always 5 ??? I can't understand it. Please help me

https://code.sololearn.com/cvM1M2t8880V/?ref=app

25th Apr 2018, 9:55 AM
WindSeaVT
WindSeaVT - avatar
2 Respostas
+ 1
b=a++ -> you are using post increment, so first you asing the value of a (5) to b then (next instruction) increments the value of a to 6. Finally you print the value of b (cout << b;) wich is 5. It doesnt matter how you initialize the value of b it always will be overwrite by the value of a.
25th Apr 2018, 10:03 AM
J Domingo Jiménez J
J Domingo Jiménez J - avatar
+ 1
That's because you assign the value of a to be and print it. a++ means that it's value is used in the expression and then incremented.
25th Apr 2018, 10:00 AM
Jonas Schröter
Jonas Schröter - avatar