You are on page 1of 1

From greatest to smallest priority, C++ operators are evaluated in the following order:

Level Precedence group Operator Description Grouping


Left-to-
1 Scope :: scope qualifier
right
++ -- postfix increment / decrement
() functional forms Left-to-
2 Postfix (unary)
[] subscript right
. -> member access
++ -- prefix increment / decrement
~ ! bitwise NOT / logical NOT
+ - unary prefix
Right-to-
3 Prefix (unary) & * reference / dereference
left
new delete allocation / deallocation
sizeof parameter pack
(type) C-style type-casting
Left-to-
4 Pointer-to-member .* ->* access pointer
right
Left-to-
5 Arithmetic: scaling * / % multiply, divide, modulo
right
Left-to-
6 Arithmetic: addition + - addition, subtraction
right
Left-to-
7 Bitwise shift << >> shift left, shift right
right
Left-to-
8 Relational < > <= >= comparison operators
right
Left-to-
9 Equality == != equality / inequality
right
Left-to-
10 And & bitwise AND
right
Left-to-
11 Exclusive or ^ bitwise XOR
right
Left-to-
12 Inclusive or | bitwise OR
right
Left-to-
13 Conjunction && logical AND
right
Left-to-
14 Disjunction || logical OR
right
= *= /= %= +=
-= assignment / compound
Assignment-level >>= <<= &= ^= assignment Right-to-
15
expressions |= left
?: conditional operator
Left-to-
16 Sequencing , comma separator
right

When an expression has two operators with the same precedence level, grouping determines which
one is evaluated first: either left-to-right or right-to-left.

Enclosing all sub-statements in parentheses (even those unnecessary because of their precedence)
improves code readability.

You might also like