Addition cpp

Could i know why is the answer 4 not 5 https://code.sololearn.com/cgeRl6r6Q3FG/?ref=app

1st Aug 2019, 7:50 PM
Majd Alkwaja
Majd Alkwaja - avatar
2 Answers
+ 4
The ++ operator works differently based on where it is in relation to the variable. In line 8 within your program, you have the value of b set to be equal to a++, and because the ++ is following the variable, the value of a will only be incremented after the value of b is set to a. Because of this, b is then set to 3 and a is set to 4. Following that on line 9, you're outputting ++b, which increments b before printing it to the console, and because the value of b is 3, ++b would be equal to 4 which is printed after the operation is performed
1st Aug 2019, 7:53 PM
Faisal - avatar
+ 1
oh thanks bro❤️❤️
1st Aug 2019, 7:54 PM
Majd Alkwaja
Majd Alkwaja - avatar