Heba Mahmoud wrote:
this output 5 as after ++y ,y become 2 then add to it y++ where y =2 in that case then 2+2 =4 then increment y to be 3 then add the left hand side operands of y to have y=y+4= 3+4= 7
First of all try to simplyfy the expression.
Actual expression is
y= y+ ++y + y++;
Here y=1. And when you say y+ that is 1+
then it comes to ++y here y becomes 2
expression is y= 1 + 2 + y++ ok?
then it becomes like this y=1 + 2 + 2 (And not 3 Because it is post increment operator so it first uses current value then
increment it.)
Thats why... finally y= 1 + 2 + 2 i.e. 5
In case of 0.... I think you can follow the above steps.
You'll get the answer as 2.