Operators take precedence from top to bottom in the following table. Operators within the same cell have equal precedence, and are executed according the the noted associativity.
Parentheses may be used to override the precedence rules; expressions enclosed in parentheses are evaluated before being operated on by the surrounding operators.
| Operator | Description | Associativity |
|---|---|---|
|
() [] |
Function call Array subscripting |
Left-to-Right |
|
+ - not |
Unary plus and minus Logical NOT |
Right-to-Left |
| ^ | Exponentiation | |
| * / % | Multiplication, division, and modulus (remainder) | Left-to-Right |
| + - | Addition and subtraction | |
|
< <= > >= == != |
Relational "less than" and "less than or equal to" Relational "greater than" and "greater than or equal to" Relational "equal to" and "not equal to" |
|
| and | Logical AND | |
| or | Logical OR | |
| = | Assignment |
"Associativity" refers to the evaluation order given a set of operators within the same table cell. Eksample: Since division associates Left-to-Right, the following two expressions will give the same result:
3.14 / 2.0 / 1.1
(3.14 / 2.0) / 1.1
And since exponentiation associates Right-to-Left, the following two are equal:
2 ^ 3 ^ 4
2 ^ (3 ^ 4)