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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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.
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.