+ 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?

2nd May 2019, 3:08 PM
Jordan Gary
Jordan Gary - avatar
3 Respuestas
+ 2
++ after the name means the value increases after the operation. So b gets a's old value 3, then a becomes 4.
2nd May 2019, 3:13 PM
HonFu
HonFu - avatar
- 1
++b
2nd May 2019, 4:21 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
- 2
Don't do that, do b=++a
2nd May 2019, 6:01 PM
Werg Serium
Werg Serium - avatar