Operator Precedence
 
When several operations occur in a single expression, each operation is evaluated and resolved in a predetermined order. This is called the order of operation or operator precedence.

If an operator in an expression has a higher precedence, it is evaluated before an operator of lower precedence.

If operators have equal precedence, they then are evaluated in the order in of their associativity. The associativity may be Left-to-Right or Right-to-Left order.

Operators that have an associativity of "N/A" indicate that there is no expression in which the operator can be used where its order of operation would need to be checked, either by precedence or by associativity. Function-like operators such as Cast are always the first to be evaluated due to the parentheses required in their syntax. And assignment operators are always the last to be evaluated.

Parentheses can be used to override operator precedence. Operations within parentheses are performed before other operations. Within the parentheses normal operator precedence is used.

The following table lists operator precedence from highest to lowest. Breaks in the table mark the groups of operators having equal precedence.

Highest Precedence

OperatorDescriptionAssociativity
   
CASTType ConversionN/A
PROCPTRProcedure pointerN/A
STRPTRString pointerN/A
VARPTRVariable pointerN/A
   
[]String indexLeft-to-Right
[]Pointer indexLeft-to-Right
()Array indexLeft-to-Right
()Function CallLeft-to-Right
.Member accessLeft-to-Right
->Pointer to member accessLeft-to-Right
   
@Address ofRight-to-Left
*Value ofRight-to-Left
NewAllocate MemoryRight-to-Left
DeleteDeallocate MemoryRight-to-Left
   
^ExponentiateLeft-to-Right
   
-NegateRight-to-Left
   
*MultiplyLeft-to-Right
/DivideLeft-to-Right
   
\Integer divideLeft-to-Right
   
MODModulusLeft-to-Right
   
SHLShift leftLeft-to-Right
SHRShift rightLeft-to-Right
   
+AddLeft-to-Right
-SubtractLeft-to-Right
   
&String concatenationLeft-to-Right
   
=EqualLeft-to-Right
<>Not equalLeft-to-Right
<Less thanLeft-to-Right
<=Less than or equalLeft-to-Right
>=Greater than or equalLeft-to-Right
>Greater thanLeft-to-Right
   
NOTComplementRight-to-Left
   
ANDConjunctionLeft-to-Right
   
ORInclusive DisjunctionLeft-to-Right
   
EQVEquivalenceLeft-to-Right
IMPImplicationLeft-to-Right
XORExclusive DisjunctionLeft-to-Right
   
ANDALSOShort Circuit ConjunctionLeft-to-Right
ORELSEShort Circuit Inclusive DisjunctionLeft-to-Right
   
=AssignmentN/A
&=Concatenate and AssignN/A
+=Add and AssignN/A
-=Subtract and AssignN/A
*=Multiply and AssignN/A
/=Divide and AssignN/A
\=Integer Divide and AssignN/A
^=Exponentiate and AssignN/A
MOD=Modulus and AssignN/A
AND=Conjunction and AssignN/A
EQV=Equivalence and AssignN/A
IMP=Implication and AssignN/A
OR=Inclusive Disjunction and AssignN/A
XOR=Exclusive Disjunction and AssignN/A
SHL=Shift Left and AssignN/A
SHR=Shift Right and AssignN/A
LETAssignmentN/A
   
LET()AssignmentN/A


Lowest Precedence

An exception to the listed operator precedence is where a Negation ( - ) operator immediately follows an Exponentiate ( ^ ) operator, in which case, the negation is evaluated first.

See also