In many of the mock SCJP exams the following type of question occurs
int x, a = 6, b = 7;
x = a++ + b++;
After execution of the code fragment above what are the values of x,a and b
The answer given is always
a = 7, b= 8 and x = 13
This is because x is evaluated as a+b and then a++ and b++ are evaluated.
I don't understand why!
According to the operator precedence rules in my java manual unary operators (++) take precedence over arithmetic operators (+).
Is there some other special rule which applies for this case - it appears that the + operator is taking precedence over the ++ operator.
int x, a = 6, b = 7;
x = a++ + b++;
After execution of the code fragment above what are the values of x,a and b
The answer given is always
a = 7, b= 8 and x = 13
This is because x is evaluated as a+b and then a++ and b++ are evaluated.
I don't understand why!
According to the operator precedence rules in my java manual unary operators (++) take precedence over arithmetic operators (+).
Is there some other special rule which applies for this case - it appears that the + operator is taking precedence over the ++ operator.