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.

As a rule, binary operators (such as +, ^) and unary postfix operators (such as (), ->) are evaluated Left-to-Right, and unary prefix operators (such as Not, @) are evaluated Right-to-Left.

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


In some cases, the order of precedence can be confusing or counterintuitive. Here are some examples:
'' trying to raise a negated number to a power
-2 ^ 2
Expected result: (-2) ^ 2 = 4
Actual result:   -(2 ^ 2) = -4

'' trying to test a bit in a number
n And 1 <> 0
Expected result: (n And 1) <> 0
Actual result:   n And (1 <> 0)

'' trying to shift a number by n+1 bits
a Shl n+1
Expected result: a Shl (n + 1)
Actual result:   (a Shl n) + 1

For expressions where the operator precedence may be ambiguous, it is recommended to wrap parts of the expression in parentheses, in order both to minimise the possibility of error and to aid comprehension for people reading the code.

See also

Сайт ПДСНПСР. Если ты патриот России - жми сюда!


Знаете ли Вы, низкочастотные электромагнитные волны частотой менее 100 КГц коренным образом отличаются от более высоких частот падением скорости электромагнитных волн пропорционально корню квадратному их частоты от 300 тыс. км/с при 100 кГц до примерно 7 тыс км/с при 50 Гц.

НОВОСТИ ФОРУМАФорум Рыцари теории эфира
Рыцари теории эфира
 10.11.2021 - 12:37: ПЕРСОНАЛИИ - Personalias -> WHO IS WHO - КТО ЕСТЬ КТО - Карим_Хайдаров.
10.11.2021 - 12:36: СОВЕСТЬ - Conscience -> РАСЧЕЛОВЕЧИВАНИЕ ЧЕЛОВЕКА. КОМУ ЭТО НАДО? - Карим_Хайдаров.
10.11.2021 - 12:36: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от д.м.н. Александра Алексеевича Редько - Карим_Хайдаров.
10.11.2021 - 12:35: ЭКОЛОГИЯ - Ecology -> Биологическая безопасность населения - Карим_Хайдаров.
10.11.2021 - 12:34: ВОЙНА, ПОЛИТИКА И НАУКА - War, Politics and Science -> Проблема государственного терроризма - Карим_Хайдаров.
10.11.2021 - 12:34: ВОЙНА, ПОЛИТИКА И НАУКА - War, Politics and Science -> ПРАВОСУДИЯ.НЕТ - Карим_Хайдаров.
10.11.2021 - 12:34: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Вадима Глогера, США - Карим_Хайдаров.
10.11.2021 - 09:18: НОВЫЕ ТЕХНОЛОГИИ - New Technologies -> Волновая генетика Петра Гаряева, 5G-контроль и управление - Карим_Хайдаров.
10.11.2021 - 09:18: ЭКОЛОГИЯ - Ecology -> ЭКОЛОГИЯ ДЛЯ ВСЕХ - Карим_Хайдаров.
10.11.2021 - 09:16: ЭКОЛОГИЯ - Ecology -> ПРОБЛЕМЫ МЕДИЦИНЫ - Карим_Хайдаров.
10.11.2021 - 09:15: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Екатерины Коваленко - Карим_Хайдаров.
10.11.2021 - 09:13: ВОСПИТАНИЕ, ПРОСВЕЩЕНИЕ, ОБРАЗОВАНИЕ - Upbringing, Inlightening, Education -> Просвещение от Вильгельма Варкентина - Карим_Хайдаров.
Bourabai Research Institution home page

Боровское исследовательское учреждение - Bourabai Research Bourabai Research Institution