The following table lists the order of precedence of all generic operators.
highest | |||
+ (unary) | - (unary) | ||
() | [] | ++ | -- |
! | ~ | ||
@ | # | $ | |
* | / | % | |
+ | - | ||
<< | >> | ||
< | > | <= | >= |
== | != | ||
& | |||
^ | |||
| | |||
&& | |||
|| | |||
= | |||
lowest |
Knowing the precedence of operators is very important when forming expressions. Parentheses can be used to alter the meaning of expressions. For example, consider the following code fragment.
a = 10 b = 20 c = 2 d = a * b + c // d is 202 e = a * (b + c) // e is 220
In the calculation of d, the multiplication takes precedence over addition and is therefore performed first. When parentheses are used to sum b and c then multiply by a, a different result is obtained.