Operator Precedence
Operator precedence determines the order in which the operators in an expression are
evaluated
Foreg-
intx=3*4-1;
In the above example, the value of x will be 11, not 9. This happens because the
precedence of * operator is higher than - operator. That is why the expression is
evaluated as (3* 4) - 1 and not 3* (4- 1)
Operator Precedence Table
Operators Precedence
postfix increment and decrement +
prefix increment and decrement, and +
unary
multiplicative
additive He
shift << )}(>>] (>>>)
relational “<)(>)(<=]>=)[instanceof_
equality
bitwise AND &
bitwise exclusive OR
bitwise inclusive OR i
logical AND 88
logical OR 1)
temary
ssignment aay feel
Associativity of OperatorsAPNA
COLLEGE
If an expression has two operators with similar precedence, the expression is
evaluated according to its associativity (either left to right, or right to left.
Operators Precedence Associativity
postfix increment and =
deorement: Lt left to right
prefix increment and MOIDOOD Iron ter
decrement, and unary
multiplicative & left to right
additive WO left to right
shift left to right
relational left to right
equality leftto right
bitwise AND (®) left to right
bitwise exclusive OR left to right
bitwise inclusive OR a
left to right
logical AND (3a) left to right
logical OR (ul left to right
temary ? right to left
assignment right to left
Note - These notes are just for quick glance. We don't have to memorize them all at
once. Most of these rules are very lo
instances already.
| and we have been following them in a lot of