C++ operator precedence

From Thought dump
Revision as of 19:03, 25 August 2024 by Jwo (talk | contribs) (Created page with "{| class="wikitable" |- ! Precedence ! Operator(s) ! Description |- | 1 | <code>::</code> | Scope resolution | → |- | 2 | <code>a++</code> <code>a--</code> | Suffix/postfix increment and decrement | → |- | 2 | <code>type()</code> <code>type{}</code> | Functional cast | → |- | 2 | <code>a()</code> | Function call | → |- | 2 | <code>a[]</code> | Subscript | → |- | 2 | <code>.</code> <code>-></code> | Member access | → |- | 3 | <code>++a</code> <code>--a</code>...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Precedence Operator(s) Description
1 :: Scope resolution
2 a++ a-- Suffix/postfix increment and decrement
2 type() type{} Functional cast
2 a() Function call
2 a[] Subscript
2 . -> Member access
3 ++a --a Prefix increment and decrement
3 +a -a Unary plus and minus
3 ! ~ Logical NOT and bitwise NOT
3 (type) C-style cast
3 *a Indirection (dereference)
3 &a Address-of
3 sizeof Size-of
3 co_await await-expression
3 new new[] Dynamic memory allocation
3 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
16 throw throw operator
16 co_yield yield-expression
16 = Direct assignment (provided by default for C++ classes)
16 += -= Compound assignment by sum and difference
16 *= /= %= Compound assignment by product, quotient, and remainder
16 <<= >>= Compound assignment by bitwise left shift and right shift
16 = Compound assignment by bitwise AND, XOR, and OR
17 , Comma