0

Who can solve my question

how can solve the question like this int a=1;int b a+=++b; cout<<a-b;

10th Feb 2017, 2:45 PM
fateme fadaee
4 Answers
+ 4
You can't because you don't know the initial value of b. Nvm, even without knowing b this should always output 1.
10th Feb 2017, 3:27 PM
Robobrine
Robobrine - avatar
+ 4
Lol @Robobrine. That initial wtf moment.
10th Feb 2017, 3:55 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
The answer is 1. Follow me closely please. Let me explain, the default value for an integer is 0 incase when you don't specify its value: so we take the value of b to be zero. when you do this "a+=++b" it is the same as "a=a+(1+b)", But our b = 0, hence the new "a", on the left is same as a= 1+(1+0)=2. For the last statement, "cout<<a-b;" it prints "a" whose value is 2 minus "b" whose value is already 1. Hence giving 1. I hope i have helped.
10th Feb 2017, 4:02 PM
Elijah
Elijah - avatar
0
oh.yes tnx
10th Feb 2017, 3:28 PM
fateme fadaee