Skip to content

Precedence

We all know that 2 + 3 * 7 is 23 and not 35. The reason is that the * operator has a higher precedence than the + operator and is, therefore, evaluated first. These precedence rules are necessary for all types of expressions listed above and shown in the following list. The higher up an expression is in the list, the higher its precedence and the earlier it is evaluated. Expressions listed beside each other have the same precedence and are evaluated from left to right:

If the default precedence of operators is not sufficient, parentheses can be used to force a part of an expression to be evaluated first.