+ 2

what is the output of this code

int b=2; int i=5; i + =++ i*b; cout<<i;

19th Feb 2018, 6:39 AM
Poonam Gaba
Poonam Gaba - avatar
3 Answers
+ 2
i += ++i*b is equivalent to i = i + ++i * b unary operators have higher precedence so ++i is evaluated first so i becomes 6 *has higher precedence next, so 6*2 is 12 then i + 12 since I has already been incremented to 6, 6+12=18 will be the result.
19th Feb 2018, 7:24 AM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
+ 3
actually 18
19th Feb 2018, 6:41 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
18
12th Mar 2018, 9:08 AM
Naman
Naman - avatar