When several operations occur in a single expression, each operation is evaluated and resolved in a predetermined order. This called the order of operation or operator precedence. There are three main categories of operators; arithmetic, comparison, and logical. If an expression contains operators from more than one category, arithmetic operators are evaluated first, comparison operators next, and finally logical operators are evaluated last. If operators have equal precedence, they then are evaluated in the order in which they appear in the expression from left to right. Comparison operators all have equal precedence.
The following table gives the
operator precedence for each operator in each category. Operators lower on the
list have a lower operator precedence. Operators on the right have lower
precedence than ALL operators in the column to the left. Arithmetic
operators are evaluated before comparison operations, and logical operators are
last.
Parentheses can be used to override operator precedence. Operations within parentheses are performed before other operation. However, within the parentheses operator precedence is used.
| Arithmetic | Comparison | Logical |
| - (Negation) | = <> < > <= >= | AND |
| *, / (Multiplication and division) | OR | |
| MOD (Modulus Operator) | XOR | |
| +, - (Addition and subtraction) | NOT | |
| <<, >> (Shift Bit Left and Shift Bit Right) |