+ 3

Why the output is 4 in both b and b++? I am not able to understand this. Kindly help.

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

16th Oct 2017, 3:09 AM
kanishka
kanishka - avatar
2 ответов
+ 12
because it prints b first, then adds 1 to it. Try ++b.
16th Oct 2017, 3:12 AM
qwerty
qwerty - avatar
+ 9
++b is pre-incrementing (add first, do stuff later) b++ is post-incrementing (do stuff first, add later)
16th Oct 2017, 3:14 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar