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.

Who is Participating?
CPColinConnect With a Mentor Senior Java ArchitectCommented:
The post-increment operator, ++, placed after a variable, returns the value first, then increments the variable. Thus the plus operator, +, gets the values 6 and 7.
mnrzConnect With a Mentor Commented:
because ++ occured after the variable so it has not preceding over the +
it means after the action increment the value
Mayank SAssociate Director - Product EngineeringCommented:
Yes, just look at it as:

x = a ++ + y ++ ;


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.
keepworkingAuthor Commented:

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?
Mayank SAssociate Director - Product EngineeringCommented:
You don't need to - its ok.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.