Operator precedence:
Operator precedence
suggest changeOperators 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_caststatic_castreinterpret_castconst_casttypeid - The unary prefix operators:
++--\*&\+\-\!~sizeofnewdeletedelete[]; the C-style cast notation,(T)...; (C++11 and above)sizeof...alignofnoexcept .*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 asa ? b , c : dto be syntactically valid. - An operand binds more tightly to a
?on its right than to an assignment operator orthrowon its left, soa = b ? c : dis equivalent toa = (b ? c : d)andthrow a ? b : cis equivalent tothrow (a ? b : c). - An operand binds more tightly to an assignment operator on its right than to
:on its left, soa ? b : c = dis equivalent toa ? b : (c = d).
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents
1
Literals
3
Operator precedence
8
Arrays
11
Loops
14
keywords
16
auto keyword
17
Pointers
20
std::string
21
Enumeration
22
std::atomic
23
std::vector
24
std::array
25
std::pair
26
std::map
29
std::any
30
std::variant
35
std::iomanip
36
Iterators
37
Basic I/O
38
File I/O
39
Streams
43
References
44
Polymorphism
51
Unions
52
Templates
53
Namespaces
56
Lambdas
57
Threading
59
Preprocessor
60
SFINAE
62
RAII
63
Exceptions
67
Sorting
74
Pimpl idiom
75
Copy elision
78
Singleton
81
Type erasure
84
RTTI
87
Scopes
88
Atomic types
90
constexpr
98
Type traits
102
Attributes
104
Profiling
107
Recursion
108
Callable objects
111
Inline functions
113
Header files
116
Parameter packs
117
Iteration
118
type deduction
120
Build systems
122
Type inference
125
Alignment
126
Inline variables
133
Optimization
134
Semaphore
136
Debugging
139
Mutexes
140
Recursive mutex
141
Unit testing
142
decltype
143
Digit separators
144
C++ Containers
146
Contributors