+ 1

How does it work?

int a=4,b; b=a+ ++a; cout <<b; the result is 10 How does it work??? what is the logic???

10th Jul 2017, 10:57 AM
Nafiseh Moghanizadeh
Nafiseh Moghanizadeh - avatar
4 ответов
+ 1
I suppose you don't understand why a + ++a = 10 Here the second 'a' is incremented before anything because of the pre-increment operator. So a=5. Then, once the '++' is executed, we have a+a with a=5. 5+5=10. Ask if you don't understand
10th Jul 2017, 11:20 AM
Jojo
+ 3
starting from right => ++a = 4+1=5, b = a + 5 => 5 + 5 = 10
10th Jul 2017, 11:09 AM
Karl T.
Karl T. - avatar
+ 1
thank you for help!!!!
10th Jul 2017, 11:22 AM
Nafiseh Moghanizadeh
Nafiseh Moghanizadeh - avatar
- 1
You're welcome :)
10th Jul 2017, 11:37 AM
Jojo