0

x=8;y=7;x++;x+=y--;

In this How it could be 16 as solution? My answer is 15

22nd Dec 2022, 4:55 AM
Amit Joe
Amit Joe - avatar
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.
22nd Dec 2022, 5:34 AM
Tibor Santa
Tibor Santa - avatar
+ 4
I understand first it assign the value to x then decrease the value of y thanks you all
22nd Dec 2022, 7:15 AM
Amit Joe
Amit Joe - avatar
+ 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
22nd Dec 2022, 5:38 AM
Ayush Singh
Ayush Singh - avatar
0
In this the y is postfix INCREMENTed so first it will add to x and then increment
23rd Dec 2022, 1:36 PM
Madipadige Manish Kumar
Madipadige Manish Kumar - avatar