0 , id , this , []{} ,
(expression) ,
(x, ...) ,
requires () {}
|
primary-expression https://eel.is/c++draft/expr.prim#:primary-expression |
Literals, identifiers, fold expressions, requires expressions, etc. These don't really have precedence, but are the building block out of which other expressions are built. |
None |
:: |
qualified-id https://eel.is/c++draft/expr.prim#nt:qualified-id |
Scope resolution https://en.cppreference.com/w/cpp/language/identifiers#Qualified_identifiers. :: is also not an operator strictly speaking, but a way of combining multiple identifiers into a single name. |
Left-to-right Binary |
x++ x--
type() type{}
x() x[]
. , ->
static_cast
typeid , ... |
postfix-expression https://eel.is/c++draft/expr.post.general#nt:postfix-expression |
Postfix expressions. Casts like static_cast are also classified as a postfix expression, although usually people don't consider it an operator and there is usually no confusion as to its precedence. |
Left-to-right Various |
++x , --x
+x -x
!x ~x
(type) x
*x &x
sizeof
co_await
new
delete
|
unary-expression https://eel.is/c++draft/expr.unary.general#nt:unary-expression |
Prefix expressions. This also includes C-style casts, co_await , new , and delete , which not everyone expects to be an operator.
Note that the operand to sizeof cannot be a C-style cast, e.g. sizeof (int)x is parsed as sizeof(int) followed by x . |
Right-to-left Various |
.* ->*
|
pm-expression https://eel.is/c++draft/expr.mptr.oper#nt:pm-expression |
Pointer-to-member operators. |
Left-to-right Binary |
* / %
|
multiplicative-expression https://eel.is/c++draft/expr.mul#nt:multiplicative-expression |
Multiplicative operators. |
|
+ -
|
additive-expression https://eel.is/c++draft/expr.add#nt:additive-expression |
Additive operators. |
|
<< >>
|
shift-expression https://eel.is/c++draft/expr.shift#nt:shift-expression |
Bitwise shift operators. |
|
<=> |
compare-expression https://eel.is/c++draft/expr.spaceship#nt:compare-expression |
Three-way comparison operator. |
|
< >
<= >=
|
relational-expression https://eel.is/c++draft/expr.rel#nt:relational-expression |
Relational comparison operators. Note that a < b < c means (a < b) < c and is likely a mistake. |
|
== !=
|
equality-expression https://eel.is/c++draft/expr.eq#nt:equality-expression |
Equality comparison operators. Note that a == b == c means (a == b) == c and is likely a mistake. |
|
& |
and-expression https://eel.is/c++draft/expr.bit.and#nt:and-expression |
Bitwise AND operator. |
|
^ |
exclusive-or-expression https://eel.is/c++draft/expr.xor#nt:exclusive-or-expression |
Bitwise XOR operator. |
|
| |
inclusive-or-expression https://eel.is/c++draft/expr.or#nt:inclusive-or-expression |
Bitwise OR operator. |
|
&& |
logical-and-expression https://eel.is/c++draft/expr.log.and#nt:logical-and-expression |
Logical AND operator. |
|
|| |
logical-or-expression https://eel.is/c++draft/expr.log.or#nt:logical-or-expression |
Logical OR operator. |
|
a?b:c |
conditional-expression https://eel.is/c++draft/expr.cond#nt:conditional-expression |
Conditional operator, colloquially called "ternary operator". Note that b is parsed as if it was parenthesized, so its precedence doesn't matter. |
Right-to-left Ternary |
= += ...
co_yield
throw
|
assignment-expression https://eel.is/c++draft/expr.ass#nt:assignment-expression |
Regular assignment and compound assignment. Also yield expression and throw expressions. |
Right-to-left Various |
, |
expression https://eel.is/c++draft/expr.comma#nt:expression |
Comma operator |
Left-to-right Binary |