Operator precedence

suggest change

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

  1. ::
  2. The postfix operators: [] () T(...) . -> ++ -- dynamic_cast static_cast reinterpret_cast const_cast typeid
  3. The unary prefix operators: ++ -- \* & \+ \- \! ~ sizeof new delete delete[]; the C-style cast notation, (T)...; (C++11 and above) sizeof... alignof noexcept
  4. .* and ->*
  5. \*, /, and %, binary arithmetic operators
  6. \+ and \-, binary arithmetic operators
  7. << and >>
  8. \<, \>, <=, >=
  9. == and !=
  10. &, the bitwise AND operator
  11. ^
  12. |
  13. &&
  14. ||
  15. ?: (ternary conditional operator)
  16. =, *=, /=, %=, +=, -=, >>=, <<=, &=, ^=, |=
  17. throw
  18. , (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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Operator precedence:

Table Of Contents
3 Operator precedence
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype