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 .
If this tool helped you, you can buy us a coffee ☕
Quickly check C++ operator precedence and associativity to help understand the evaluation order of complex expressions.
::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)When writing C++ code, complex expressions often lead to logic errors due to unclear operator precedence and associativity. This tool helps you quickly check the precedence level and associativity direction (left-to-right or right-to-left) of any C++ operator. Through a dynamic table and search input, it simplifies the process of browsing standard documentation into an instant online query. It outputs the operator's rank, associativity, and typical usage, making the evaluation order of expressions clear at a glance.
==, &&, >>) or type a keyword like "logical AND".* outputs precedence 5, "Left-to-right" associativity, and the description "Multiplication / Dereference".:: has a precedence of 1 (highest), while the comma operator has a precedence of 17 (lowest).a = b = c assign correctly? Associativity determines the direction of evaluation when operators have the same precedence. The assignment operator = is right-to-left associative, so a = b = c is evaluated as a = (b = c). The query results clearly indicate the associativity of each operator to prevent misinterpretation.This tool is based on the operators and precedence levels listed in the ISO C++ standard, covering major versions from C++98 to C++23, but does not include compiler-specific extensions. Please use half-width characters when searching by symbol. The results serve as a coding reference; in actual expressions, it is recommended to use parentheses to improve readability. This tool operates entirely on the frontend and will not save or upload your queries, ensuring your privacy. If an entered symbol is not recognized, please check your spelling or browse the complete precedence list directly.
Operator precedence and associativity remain unchanged when operators are overloaded; you cannot alter their precedence through overloading. In template metaprogramming or macro definitions, properly using parentheses is much safer than relying on default precedence. A classic example: cout << a & b; will cause a compilation error because the bitwise AND & has lower precedence than the bitwise shift operator. It should be written as cout << (a & b);. If you are unsure about the relative order of an operator, use this tool to check the precedence table at any time to effectively avoid such precedence traps.
C/C++ Code Formatter & Beautifier
Free online C/C++ code formatter and beautifier. Quickly standardize indentation, brace styles, and format your C and C++ code instantly.

JSON to C++ Struct Converter
Automatically map JSON data structures to C++ class or struct definitions for rapid generation of data models used in APIs and configuration files.

URL to JSON Parser
Parse URL strings into structured JSON to quickly extract key information like protocols, parameters, and paths.

JSON Formatter
Process JSON data online: format, minify, and validate to boost your development and debugging efficiency.
C/C++ Code Formatter & Beautifier
Free online C/C++ code formatter and beautifier. Quickly standardize indentation, brace styles, and format your C and C++ code instantly.

JSON to C++ Struct Converter
Automatically map JSON data structures to C++ class or struct definitions for rapid generation of data models used in APIs and configuration files.

URL to JSON Parser
Parse URL strings into structured JSON to quickly extract key information like protocols, parameters, and paths.

JSON Formatter
Process JSON data online: format, minify, and validate to boost your development and debugging efficiency.

PYC Decompiler
Restore Python bytecode .pyc files into readable source code for easy code auditing and learning. Supports mainstream versions.