We use cookies.This website uses essential cookies to operate core features. With your consent, we also use analytics cookies to understand traffic and improve the service. For more details, see our .
Was this tool helpful to use?
Your feedback helps us make it better
Quickly check C++ operator precedence and associativity to help understand the evaluation order of complex expressions.
A curated syntax reference, not a compiler or example validator. Local group numbers do not replace version-specific grammar, typing or evaluation rules. Examples keep their original code and literals. Reference
::Scope ResolutionLeft限定命名空间、类或枚举的成员,如 std::cout、Foo::bar。
std::vector<int>a++PostfixLeft返回当前值后将变量加 1。
i++a--PostfixLeft返回当前值后将变量减 1。
i--type()PostfixLeft通过类似构造函数调用的形式进行类型转换。
int(3.14)type{}PostfixLeftC++11 起使用花括号进行类型转换或临时对象初始化。
double{1}a()PostfixLeft调用函数、函数对象或仿函数。
std::printf("hi")a[]PostfixLeft访问数组、容器或重载了 operator[] 的对象的元素。
arr[0].PostfixLeft访问对象的非指针成员(字段、方法)。
obj.name->PostfixLeft通过指针访问对象的成员,等价于 (*p).x。
p->next++aUnaryRight先将变量加 1,再返回新值。
++i--aUnaryRight先将变量减 1,再返回新值。
--i+aUnaryRight返回操作数的值,触发整型提升。
+x-aUnaryRight返回操作数的相反数。
-x!UnaryRight对布尔值取反,0/false 变为 true,否则为 false。
!ready~UnaryRight对整数按位取反,每一位 0 变 1、1 变 0。
~mask(type)UnaryRight将表达式显式转换为目标类型,能力强但安全性低。
(int)3.14*aUnaryRight读取指针指向的对象。
*p&aUnaryRight获取对象在内存中的地址。
&valuesizeofUnaryRight返回类型或表达式占用的字节数,编译期求值。
sizeof(int)co_awaitUnaryRightC++20 起暂停协程并等待 awaitable 的结果。
co_await tasknewUnaryRight在堆上分配并构造对象,返回指针。
new int(5)new[]UnaryRight在堆上分配数组并构造元素。
new int[10]deleteUnaryRight析构并释放由 new 分配的单个对象。
delete pdelete[]UnaryRight析构并释放由 new[] 分配的数组。
delete[] arr.*Pointer to MemberLeft通过成员指针访问对象的成员。
(obj.*memPtr)->*Pointer to MemberLeft通过指针和成员指针访问对象的成员。
(ptr->*memPtr)*MultiplicativeLeft两个操作数相乘。
a * b/MultiplicativeLeft整数除法向零截断;浮点除法保留小数。
10 / 3%MultiplicativeLeft返回整数相除的余数,操作数必须为整型。
10 % 3+AdditiveLeft两个数值相加,或指针与整数相加。
a + b-AdditiveLeft两数相减,或两个指针相减得到偏移量。
a - b<<ShiftLeft整数按位左移,或在 iostream 中表示流输出。
1 << 3>>ShiftLeft整数按位右移,或在 iostream 中表示流输入。
8 >> 2<=>SpaceshipLeftC++20 起返回 std::strong_ordering / weak_ordering / partial_ordering。
a <=> b<RelationalLeft比较两个操作数,左小于右返回 true。
a < b<=RelationalLeft左小于或等于右返回 true。
a <= b>RelationalLeft比较两个操作数,左大于右返回 true。
a > b>=RelationalLeft左大于或等于右返回 true。
a >= b==EqualityLeft判断两个值是否相等。
a == b!=EqualityLeft判断两个值是否不相等。
a != b&BitwiseLeft两个整数按位执行逻辑与。
a & b^BitwiseLeft两个整数按位执行异或,相同为 0,不同为 1。
a ^ b|BitwiseLeft两个整数按位执行逻辑或。
a | b&&LogicalLeft短路逻辑与:左操作数为 false 时不计算右操作数。
a && b||LogicalLeft短路逻辑或:左操作数为 true 时不计算右操作数。
a || b?:ConditionalRight根据条件返回两个表达式之一。
x > 0 ? 1 : -1throwConditionalRight抛出异常对象,由匹配的 catch 捕获。
throw std::runtime_error("err")co_yieldConditionalRightC++20 起从生成器协程中产出一个值。
co_yield value=AssignmentRight将右操作数的值赋给左操作数。
x = 10+=AssignmentRightx = x + y 的简写。
x += 1-=AssignmentRightx = x - y 的简写。
x -= 1*=AssignmentRightx = x * y 的简写。
x *= 2/=AssignmentRightx = x / y 的简写。
x /= 2%=AssignmentRightx = x % y 的简写。
x %= 3<<=AssignmentRightx = x << y 的简写。
x <<= 2>>=AssignmentRightx = x >> y 的简写。
x >>= 2&=AssignmentRightx = x & y 的简写。
x &= 0xFF^=AssignmentRightx = x ^ y 的简写。
x ^= mask|=AssignmentRightx = x | y 的简写。
x |= 0x01,CommaLeft依次求值左、右操作数,结果为右操作数的值。常用于 for 语句的步进表达式。
for (int i=0,j=9; i<j; ++i,--j)Overview
Understand what the tool solves, how it works, and the boundaries of its data.
This reference filters a built-in C++ operator table by symbol, name, description, example, precedence number, category, and associativity. Results show each matching operator’s category, associativity, description, example, and numbered precedence level. In the table, a lower number means higher precedence.
Precedence determines how an expression is grouped when operators of different precedence appear together. Associativity resolves grouping among operators at the same level. For example, multiplication binds more tightly than addition, so a + b * c groups as a + (b * c). The table’s numbers are a browsing aid; they are not values you place in code.
These rules describe parsing and grouping. They do not by themselves tell you the runtime order in which operands are evaluated. Use parentheses to make intended grouping clear, and consult the C++ language rules when evaluation sequencing matters.
Guide
Follow the workflow and verify inputs and outputs with practical examples.
Enter a symbol, operator name, keyword, example text, or precedence number in the search field. For instance, search <=> for the three-way comparison operator.
Choose a category such as additive, logical, or assignment to limit the results.
Use the associativity filter to show left-associative, right-associative, or non-associative entries.
Read the result card’s precedence level, associativity, description, and example. Copy a symbol or example if you need to paste it into notes or code.
Filters can be combined. Clear the keyword and return the category and associativity filters to All to browse the full table again.
Use cases
See how the tool fits into real work and everyday tasks.
When reviewing a mixed arithmetic expression, look up the operators and rewrite the intended grouping with parentheses. This makes the parse easier for a reader to verify.
Students can filter one operator family at a time, then compare the examples and associativity labels. Treat the example as a reference aid and verify language-version details for advanced syntax.
Q&A
Find concise answers to common questions and confusing cases.
No. The number indicates relative grouping in the expression. Runtime sequencing and operand evaluation order follow separate C++ rules.
It shows how operators at the same precedence level group. For example, left associativity groups a - b - c as (a - b) - c; it is not a general promise that every operand is evaluated left to right.
No. It filters a reference table; it does not accept a full expression, build a parse tree, compile code, or report runtime behavior.
The search checks symbols, names, descriptions, examples, and the numeric level. A broad word or number can match several entries; add a category or associativity filter to narrow the list.
Notes
Review scope, result limitations, and important precautions before use.
The table is a quick lookup for built-in operator grouping. It is not a compiler or complete language specification, and it does not evaluate expressions. For version-sensitive syntax, overloaded operators, or sequencing questions, confirm the applicable C++ standard and compiler documentation; add parentheses when they improve clarity.
Related
Discover related tools, collections, and available API capabilities.