C++ operator precedence
Jump to navigation
Jump to search
Precedence | Operator(s) | Description | Ass. |
---|---|---|---|
1 | ::
|
Scope resolution | → |
2 | a++ a--
|
Suffix/postfix increment and decrement | → |
type() type{}
|
Functional cast | → | |
a()
|
Function call | → | |
a[]
|
Subscript | → | |
. ->
|
Member access | → | |
3 | ++a --a
|
Prefix increment and decrement | ← |
+a -a
|
Unary plus and minus | ← | |
! ~
|
Logical NOT and bitwise NOT | ← | |
(type)
|
C-style cast | ← | |
*a
|
Indirection (dereference) | ← | |
&a
|
Address-of | ← | |
sizeof
|
Size-of | ← | |
co_await
|
await-expression | ← | |
new new[]
|
Dynamic memory allocation | ← | |
delete delete[]
|
Dynamic memory deallocation | ← | |
4 | .* ->*
|
Pointer-to-member | → |
5 | a*b a/b a%b
|
Multiplication, division, and remainder | → |
6 | a+b a-b
|
Addition and subtraction | → |
7 | << >>
|
Bitwise left shift and right shift | → |
8 | <=>
|
Three-way comparison operator | → |
9 | < <= > >=
|
For relational operators < and ≤ and > and ≥ respectively | → |
10 | == !=
|
For equality operators = and ≠ respectively | → |
11 | a&b
|
Bitwise AND | → |
12 | ^
|
Bitwise XOR (exclusive or) | → |
13 | |
|
Bitwise OR (inclusive or) | → |
14 | &&
|
Logical AND | → |
15 | ||
|
Logical OR | → |
16 | … ? … : …
|
Ternary conditional | ← |
throw
|
throw operator | ← | |
co_yield
|
yield-expression | ← | |
=
|
Direct assignment (provided by default for C++ classes) | ← | |
+= -=
|
Compound assignment by sum and difference | ← | |
*= /= %=
|
Compound assignment by product, quotient, and remainder | ← | |
<<= >>=
|
Compound assignment by bitwise left shift and right shift | ← | |
= | Compound assignment by bitwise AND, XOR, and OR | ← | |
17 | ,
|
Comma | → |