+ 3

What's the output of this code? Why?

int main() { int a,b; a=10; b=++a + ++a + ++a; cout<<b; return 0; }

9th Feb 2018, 5:50 AM
Nguyễn NhÆ° CÆ°ÆĄng
Nguyễn NhÆ° CÆ°ÆĄng - avatar
4 Answers
+ 20
The output is 37đŸ€”đŸ€”đŸ€”đŸ€” For multiple pre & post increments/decrements standard is not define, so it depends on compiler... the 1st two variable when incremented both gets the value of 2nd variable .... then the increment is done normally... here :- b=(++a + ++a) + ++a b=(++11 + ++11) + ++12 = 12+12+13 =37 for eg:- b= ++a + ++a + ++a + ++a; b=(++11 + ++11) + ++12 + ++13 = 12+12+13+14 = 51
9th Feb 2018, 6:27 AM
🌛DT🌜
🌛DT🌜 - avatar
+ 12
b=++10 + ++11 + ++12 = 11+12+13 =36 & a=13 //edit : in java
9th Feb 2018, 6:07 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 11
c,c++ is confusing , java is clear language //after seeing DT's answer 😃
9th Feb 2018, 6:46 AM
Gaurav Agrawal
Gaurav Agrawal - avatar