+ 1

Why is the output 19?

https://code.sololearn.com/cqM013SZoMsk/?ref=app Please reply, its urgent.

10th Sep 2017, 9:04 AM
Mehul
Mehul - avatar
2 Answers
+ 2
i think I got it. so the reason it is 19 and not 18 is that first you i crement i so it is 5 now. so you are now with: i = 5 + ++i + ++i; but!!! 5 is still the variable i! so if you incement the next 'i', this 5 is also incremented cause it is still 'i', so you end up with: i = 6 + 6 + ++i 6 + 6 is a sum, so 12. 12 is no longer 'i', just a number. so after next incrementation, where i is equal to 7, you add 7 to the existing 12. i = 12 + 7 which is 19! or I may be wrong, but in my theorem it should work
10th Sep 2017, 9:30 AM
Paul
+ 1
thanks paul
10th Sep 2017, 9:31 AM
Mehul
Mehul - avatar