Link to home
Start Free TrialLog in
Avatar of keepworking
keepworking

asked on

x = a++ + y++; what is x?

int x, a=6, y=7;
x = a++ + y++;

x will be 13,
but I think ++ has high precendence than + ,
so a++, y++ will be exercuted before +,
so I think x should be 15.

please let me know what is wrong in my think.

ASKER CERTIFIED SOLUTION
Avatar of CPColin
CPColin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mayank S
Yes, just look at it as:

x = a ++ + y ++ ;

becomes

x = ( a ++ ) + ( y ++ ) ;

So a ++ and y ++ are evaluated first (as the current values of a and y respectively) and then added to be assigned to x. The values of a and y are then incremented after the statement.
Avatar of keepworking
keepworking

ASKER

mayankeagle:

it seems yu added the comment during I was closing it, so I missed yours, I am sorry. how to add points to you now?
You don't need to - its ok.