Operator Precedence and Associativity

— a table.

Table 11. Operator Precedence and Associativity

PrecedenceOperatorAssociativity
LowestELSERight
 [equals]Right
 [verbar] [verbar]Left
 & &Left
 <, >, < [equals], > [equals], [equals] [equals], [excl ] [equals]Left
 [verbar], &Left
 -, [plus ]Left
 Unary -, [plus ], [excl ]Left
 ^Left
 [plus ] [plus ], --Left
 [lsqb ] [rsqb ]Left
 ., ..Left
 [lpar ] [rpar ]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 [quot ] + [quot ] 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.

See Also

Arithmetic Operators, Assignment Operators, Bitwise Operators, Comparison Operators, Increment and Decrement Operators, Logical Operators, Quote Operators