Precedence and Associativity of Operators

Operators have a set order of precedence during evaluation. Items enclosed in parenthesis are evaluated first and have the highest precedence.

When several operators with equal precedence appear in the same statement, they are evaluated according to their associativity. For example, + and - have the same level of precedence and associate from left to right, therefore a-b+c is evaluated as (a-b) + c. The assignment operator = associates from right to left, therefore a=b=c=89 is evaluted as a = (b = (c = 89)).

The following chart shows the order of precedence with the items at the top having highest precedence.

Operator Associativity
::  
»  
.  
[], {}, ()  
#, @ left to right
'  
!, », ++, -  
^, .^  
&*, &/  
*, /, %, .*, ./ left to right
+, - left to right
/  
>-<, <->, <-<, >->, =>  
to, ==, >, <, !=, >=, <=  
&&, in, (-, -), (=, =), (<, >)  
||  
<>  
->  
=, +=, -=, *=, .*=, %=, /=, ./=, ^=, .^=, » right to left

oz 2009-12-22