What are order of precedence and associativity how are they used

What are order of precedence and associativity how are they used ?

Answer : Please have below operators and list are in according to its precedence order and some points:

  • Table top starts from highest precedence.
  • Those operators who has higher precedence will be evaluated before compare to operators with lower precedence
  • When operators are on same line they will have equal precedence
  • If operators of equal precedence appears in same expression then a rule will govern which will be evaluated first
  • All binary operators except for the assignment operators will be evaluated from left to right
  • Assignment operators will be evaluated from right to left

Operator Precedence

Operators Precedence
postfix expr++ expr–
unary ++expr –expr +expr -expr ~ !
multiplicative * / %
additive + –
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=

Leave a Reply

Your email address will not be published. Required fields are marked *