Table 1. Operator Precedence and Associativity
| Precedence | Operator | Associativity |
|---|---|---|
| Lowest | ELSE | Right |
| = | Right | |
| | | | Left | |
| & & | Left | |
| <, >, < =, > =, = =, ! = | Left | |
| |, & | Left | |
| -, + | Left | |
| Unary -, +, ! | Left | |
| ^ | Left | |
| + +, -- | Left | |
| [ ] | Left | |
| ., .. | Left | |
| ( ) | Left | |
| Highest | # | Left |
The associativity of operators refers to order in which repeated use of the same operator will be evaluated. For example, the expression 1+2+3 will be evaluated as (1+2)+3 since the " + " operator associates the leftmost operator instances first. In contrast, the statement A = B = C will first perform the B = C assignment, and then the result is assigned to A.
Associativity should not be confused with precedence, which determines which one of different operators will be evaluated first. In the example 1+2_3+4, the multiplication is performed first due to precedence, while the left addition is performed before the rightmost addition due to associativity, causing the expression to be evaluated as (1+(2_3))+4.
Arithmetic Operators, Assignment Operators, Bitwise Operators, Comparison Operators, Increment and Decrement Operators, Logical Operators, Quote Operators