Operator precedence in expressions

The rules that determine the order for evaluating an expression with more than one operator are:
  • An operator in a statement enclosed in parentheses takes precedence over operators that are not.
  • Operators of unequal precedence are evaluated according to precedence, from highest to lowest.
  • Operators of the same precedence are evaluated from left to right.
Operators not enclosed in parentheses are evaluated as follows:
Precedence Level
Name
Symbols
1 (Highest)
Parentheses
( )
2
logical negation
bitwise complement
NOT
~
3
Multiplication
division
modulus (remainder)
exponent
logical and
bitwise and
bitwise right shift
bitwise left shift
*
/
MOD, %
**
AND, &&
&
>>
<<
4
Addition
subtraction
logical or
bitwise inclusive or
bitwise exclusive or
functions
+
-
OR, ||
|
^
5 (lowest)
Equal
not equal
less than
greater than
less than or equal to
greater than or equal to
EQ, ==
NE, <>
LT, <
GT, >
LE, <=
GE, >=
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal