+ 1
C++ beginner question
Why does int a = 3; int b = 2; b = a++; cout << b; Print as just the number 3? I saw it as b changing to the value of a then adding 1, apparently this isnât the case. Whatâs actually happening?
3 Answers
+ 2
++ after the name means the value increases after the operation.
So b gets a's old value 3, then a becomes 4.
- 1
++b
- 2
Don't do that, do b=++a