CS/자료구조, 알고리즘
C++ Operator Precedence
joaa
2021. 12. 5. 16:50
C++ Operator Precedence
The following table lists the precedence and associativity of C++ operators. Operators are listed top to bottom, in descending precedence.
PrecedenceOperatorDescriptionAssociativity1234567891011121314151617:: | Scope resolution | Left-to-right |
a++ a-- | Suffix/postfix increment and decrement | |
type() type{} | Functional cast | |
a() | Function call | |
a[] | Subscript | |
. -> | Member access | |
++a --a | Prefix increment and decrement | Right-to-left |
+a -a | Unary plus and minus | |
! ~ | Logical NOT and bitwise NOT | |
(type) | C-style cast | |
*a | Indirection (dereference) | |
&a | Address-of | |
sizeof | Size-of[note 1] | |
co_await | await-expression (C++20) | |
new new[] | Dynamic memory allocation | |
delete delete[] | Dynamic memory deallocation | |
.* ->* | Pointer-to-member | Left-to-right |
a*b a/b a%b | Multiplication, division, and remainder | |
a+b a-b | Addition and subtraction | |
<< >> | Bitwise left shift and right shift | |
<=> | Three-way comparison operator (since C++20) | |
< <= > >= | For relational operators < and ≤ and > and ≥ respectively | |
== != | For equality operators = and ≠ respectively | |
& | Bitwise AND | |
^ | Bitwise XOR (exclusive or) | |
| | Bitwise OR (inclusive or) | |
&& | Logical AND | |
|| | Logical OR | |
a?b:c | Ternary conditional[note 2] | Right-to-left |
throw | throw operator | |
co_yield | yield-expression (C++20) | |
= | 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 | |
, | Comma | Left-to-right |
https://en.cppreference.com/w/cpp/language/operator_precedence