0
x=8;y=7;x++;x+=y--;
In this How it could be 16 as solution? My answer is 15
5 Answers
+ 4
x++ is post-increment and y-- is post-decrement. That means: use the original value inside the statement, and THEN change the variable.
After the statement x++;
x = 9 and y = 7
So the statement of x+=y--; means:
Take the value of x and y
Add them together
Assign the result to x
And finally decrement y by 1.
Therefore x becomes 16.
+ 4
I understand first it assign the value to x then decrease the value of y thanks you all
+ 3
The answer will be 16.
Let me explain,
I think you are taking 6 as value for y.
(y--) is post increament means, it will first use that value then it will increament it.
Hence, in the third line y will be first used as 7, then the system will store 6 for y for further use.
I hope i have cleared your doubt
0
In this the y is postfix INCREMENTed so first it will add to x and then increment