+ 3
What's the output of this code? Why?
int main() { int a,b; a=10; b=++a + ++a + ++a; cout<<b; return 0; }
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
+ 12
b=++10 + ++11 + ++12
= 11+12+13
=36
& a=13
//edit : in java
+ 11
c,c++ is confusing , java is clear language
//after seeing DT's answer đ