If this tool helped you, you can buy us a coffee ☕
在线查看C语言运算符优先级与结合性,助你理解表达式求值。
a++tools.leve-c-query.categories.postfixtools.leve-c-query.associativity.left先返回当前值,然后将变量加 1。
i++a--tools.leve-c-query.categories.postfixtools.leve-c-query.associativity.left先返回当前值,然后将变量减 1。
i--a()tools.leve-c-query.categories.postfixtools.leve-c-query.associativity.left调用函数并传递参数。
printf("hi")a[]tools.leve-c-query.categories.postfixtools.leve-c-query.associativity.left访问数组的元素,等价于 *(a+i)。
arr[0].tools.leve-c-query.categories.postfixtools.leve-c-query.associativity.left访问结构体或联合体的成员。
obj.name->tools.leve-c-query.categories.postfixtools.leve-c-query.associativity.left通过指针访问结构体或联合体成员,等价于 (*p).x。
p->next(type){list}tools.leve-c-query.categories.postfixtools.leve-c-query.associativity.leftC99 起在表达式中创建一个匿名对象并初始化。
(int[]){1,2,3}++atools.leve-c-query.categories.unarytools.leve-c-query.associativity.right先将变量加 1,再返回新值。
++i--atools.leve-c-query.categories.unarytools.leve-c-query.associativity.right先将变量减 1,再返回新值。
--i+atools.leve-c-query.categories.unarytools.leve-c-query.associativity.right返回操作数的值,触发整型提升。
+x-atools.leve-c-query.categories.unarytools.leve-c-query.associativity.right返回操作数的相反数。
-x!tools.leve-c-query.categories.unarytools.leve-c-query.associativity.right对操作数取反,0 变 1,非 0 变 0。
!ready~tools.leve-c-query.categories.unarytools.leve-c-query.associativity.right对整数按位取反,0 变 1,1 变 0。
~mask(type)tools.leve-c-query.categories.unarytools.leve-c-query.associativity.right将表达式显式转换为目标类型。
(int)3.14*atools.leve-c-query.categories.unarytools.leve-c-query.associativity.right读取指针所指向地址处的值。
*p&atools.leve-c-query.categories.unarytools.leve-c-query.associativity.right获取变量在内存中的地址。
&valuesizeoftools.leve-c-query.categories.unarytools.leve-c-query.associativity.right返回类型或表达式占用的字节数,编译期求值。
sizeof(int)_Alignoftools.leve-c-query.categories.unarytools.leve-c-query.associativity.rightC11 起返回类型的对齐字节数。
_Alignof(double)*tools.leve-c-query.categories.multiplicativetools.leve-c-query.associativity.left两个操作数相乘。
a * b/tools.leve-c-query.categories.multiplicativetools.leve-c-query.associativity.left整数除法向零截断;浮点除法保留小数。
10 / 3%tools.leve-c-query.categories.multiplicativetools.leve-c-query.associativity.left返回两个整数相除的余数,操作数必须为整型。
10 % 3+tools.leve-c-query.categories.additivetools.leve-c-query.associativity.left两数相加,或指针与整数相加得到偏移地址。
a + b-tools.leve-c-query.categories.additivetools.leve-c-query.associativity.left两数相减,或两个指针相减得到偏移元素个数。
a - b<<tools.leve-c-query.categories.shifttools.leve-c-query.associativity.left整数按位左移,相当于乘以 2 的幂。
1 << 3>>tools.leve-c-query.categories.shifttools.leve-c-query.associativity.left整数按位右移,有符号数实现定义、无符号数为逻辑右移。
8 >> 2<tools.leve-c-query.categories.relationaltools.leve-c-query.associativity.left比较两个操作数,左小于右返回 1,否则返回 0。
a < b<=tools.leve-c-query.categories.relationaltools.leve-c-query.associativity.left左小于或等于右返回 1,否则返回 0。
a <= b>tools.leve-c-query.categories.relationaltools.leve-c-query.associativity.left左大于右返回 1,否则返回 0。
a > b>=tools.leve-c-query.categories.relationaltools.leve-c-query.associativity.left左大于或等于右返回 1,否则返回 0。
a >= b==tools.leve-c-query.categories.equalitytools.leve-c-query.associativity.left判断两个值是否相等。
a == b!=tools.leve-c-query.categories.equalitytools.leve-c-query.associativity.left判断两个值是否不相等。
a != b&tools.leve-c-query.categories.bitwisetools.leve-c-query.associativity.left两个整数按位执行逻辑与,两位都为 1 时结果为 1。
a & b^tools.leve-c-query.categories.bitwisetools.leve-c-query.associativity.left两个整数按位执行异或,相同为 0、不同为 1。
a ^ b|tools.leve-c-query.categories.bitwisetools.leve-c-query.associativity.left两个整数按位执行逻辑或,任一位为 1 结果为 1。
a | b&&tools.leve-c-query.categories.logicaltools.leve-c-query.associativity.left短路逻辑与:左操作数为 0 时不计算右操作数。
a && b||tools.leve-c-query.categories.logicaltools.leve-c-query.associativity.left短路逻辑或:左操作数为非 0 时不计算右操作数。
a || b?:tools.leve-c-query.categories.conditionaltools.leve-c-query.associativity.right根据条件返回两个表达式之一。
x > 0 ? 1 : -1=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.right将右操作数的值赋给左操作数。
x = 10+=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.rightx = x + y 的简写。
x += 1-=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.rightx = x - y 的简写。
x -= 1*=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.rightx = x * y 的简写。
x *= 2/=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.rightx = x / y 的简写。
x /= 2%=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.rightx = x % y 的简写。
x %= 3<<=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.rightx = x << y 的简写。
x <<= 2>>=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.rightx = x >> y 的简写。
x >>= 2&=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.rightx = x & y 的简写。
x &= 0xFF^=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.rightx = x ^ y 的简写。
x ^= mask|=tools.leve-c-query.categories.assignmenttools.leve-c-query.associativity.rightx = x | y 的简写。
x |= 0x01,tools.leve-c-query.categories.commatools.leve-c-query.associativity.left依次求值左、右操作数,整个表达式的结果为右操作数的值,常用于 for 语句步进。
for (i=0,j=9; i<j; ++i,--j)在编写或阅读C语言代码时,经常因运算符优先级和结合性不熟悉而导致表达式求值错误。本工具提供C语言全部运算符的优先级顺序和结合方向一览表,并支持交互式查询,帮助你快速确认任意运算符的优先级高低和结合性,从而准确理解或编写复杂表达式。
本工具展示的优先级表基于标准C语言(C89/C99/C11),请留意不同特定编译器扩展运算符可能未包含在内。查询结果仅供参考,建议结合代码逻辑进行验证。工具为纯前端运行,不会上传任何输入内容,保护您的隐私。如在表格中未找到需要的运算符,可能是该运算符不被标准C支持或属于预处理器指令。
熟练掌握运算符优先级能减少不必要的括号,提升代码可读性和执行效率。但考虑到可维护性,在可能产生歧义的表达式中使用括号明确意图是良好实践。例如,表达式 (a & mask) == b 中按位与的优先级低于关系运算符,需加括号确保先进行位运算。建议定期参考本工具进行复习或作为编码时快速检查的辅助。