# Operator precedence

Operators are listed top to bottom, in descending precedence. Operators with the same number have equal precedence and the same associativity.

`::`

- The postfix operators:
`[]`

`()`

`T(...)`

`.`

`->`

`++`

`--`

`dynamic_cast`

`static_cast`

`reinterpret_cast`

`const_cast`

`typeid`

- The unary prefix operators:
`++`

`--`

`\*`

`&`

`\+`

`\-`

`\!`

`~`

`sizeof`

`new`

`delete`

`delete[]`

; the C-style cast notation,`(T)...`

; (C++11 and above)`sizeof...`

`alignof`

`noexcept`

`.*`

and`->*`

`\*`

,`/`

, and`%`

, binary arithmetic operators`\+`

and`\-`

, binary arithmetic operators`<<`

and`>>`

`\<`

,`\>`

,`<=`

,`>=`

`==`

and`!=`

`&`

, the bitwise AND operator`^`

`|`

`&&`

`||`

`?:`

(ternary conditional operator)`=`

,`*=`

,`/=`

,`%=`

,`+=`

,`-=`

,`>>=`

,`<<=`

,`&=`

,`^=`

,`|=`

`throw`

`,`

(the comma operator)

The assignment, compound assignment, and ternary conditional operators are right-associative. All other binary operators are left-associative.

The rules for the ternary conditional operator are a bit more complicated than simple precedence rules can express.

- An operand binds less tightly to a
`?`

on its left or a`:`

on its right than to any other operator. Effectively, the second operand of the conditional operator is parsed as though it is parenthesized. This allows an expression such as`a ? b , c : d`

to be syntactically valid. - An operand binds more tightly to a
`?`

on its right than to an assignment operator or`throw`

on its left, so`a = b ? c : d`

is equivalent to`a = (b ? c : d)`

and`throw a ? b : c`

is equivalent to`throw (a ? b : c)`

. - An operand binds more tightly to an assignment operator on its right than to
`:`

on its left, so`a ? b : c = d`

is equivalent to`a ? b : (c = d)`

.

Found a mistake? Have a question or improvement idea?
Let me know.

**Operator precedence/**

Table Of Contents

2
Literals

4
Operator precedence

9
Arrays

10
Flow control

11
Loops

15
keywords

17
auto keyword

18
Pointers

21
std::string

22
Enumeration

23
std::atomic

24
std::vector

25
std::array

26
std::pair

27
std::map

30
std::any

31
std::variant

36
std::iomanip

37
Iterators

38
Basic I/O

39
File I/O

40
Streams

44
References

45
Polymorphism

52
Unions

53
Templates

54
Namespaces

57
Lambdas

58
Threading

60
Preprocessor

61
SFINAE

63
RAII

64
Exceptions

68
Sorting

75
Pimpl idiom

76
Copy elision

79
Singleton

82
Type erasure

85
RTTI

88
Scopes

89
Atomic types

91
constexpr

99
Type traits

103
Attributes

105
Profiling

108
Recursion

109
Callable objects

112
Inline functions

114
Header files

117
Parameter packs

118
Iteration

119
type deduction

121
Build systems

123
Type inference

126
Alignment

127
Inline variables

134
Optimization

135
Semaphore

137
Debugging

140
Mutexes

141
Recursive mutex

142
Unit testing

143
decltype

144
Digit separators

145
C++ Containers

147
Contributors