+ 1

I dont understand how dis code fives me 4

int a=3 int b=2 b=a++ cout<<++b. and ans is 4?

3rd Dec 2016, 4:10 AM
E.K AUTRON
E.K AUTRON - avatar
2 Answers
+ 3
b = a++ assigns b to the current value of a which is 3. After the assignment is done, a is incremented. ++b on the other hand increments b to 4 and returns that value. You may want to look up post increment and pre increment to learn more.
3rd Dec 2016, 4:24 AM
James Durand
James Durand - avatar
+ 1
b=a++ So now b=a, which is 3, and you added one to a, so it's 4. ++b is 1+b which is 1+3, so the answer is 4.
3rd Dec 2016, 4:24 AM
Ash Ketchum
Ash Ketchum - avatar