0
Who can solve my question
how can solve the question like this int a=1;int b a+=++b; cout<<a-b;
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.
+ 4
Lol @Robobrine. That initial wtf moment.
+ 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.
0
oh.yes tnx