当前位置: 首页 > news >正文

C++ 运算符的优先级和关联性表

C++ 运算符的优先级和关联性表

  • 1. Precedence and associativity (优先级和结合性)
  • 2. Alternative spellings (替代拼写)
  • 3. C++ operator precedence and associativity table (C++ 运算符的优先级和关联性表)
  • References

C++ documentation (C++ 文档)
https://learn.microsoft.com/en-us/cpp/cpp/
https://learn.microsoft.com/zh-cn/cpp/cpp/

C++ built-in operators, precedence, and associativity (C++ 内置运算符、优先级和关联性)
https://learn.microsoft.com/en-us/cpp/cpp/cpp-built-in-operators-precedence-and-associativity
https://learn.microsoft.com/zh-cn/cpp/cpp/cpp-built-in-operators-precedence-and-associativity

The C++ language includes all C operators and adds several new operators. Operators specify an evaluation to be performed on one or more operands.
C++ 语言包括所有 C 运算符,并添加多个新的运算符。运算符指定对一个或多个操作数执行的计算。

1. Precedence and associativity (优先级和结合性)

Operator precedence specifies the order of operations in expressions that contain more than one operator. Operator associativity specifies whether, in an expression that contains multiple operators with the same precedence, an operand is grouped with the one on its left or the one on its right.
运算符优先级指定了包含多个运算符的表达式中的运算顺序。运算符关联性指定了在包含多个具有相同优先级的运算符的表达式中,操作数是与其左侧还是右侧的操作数组合。

precedence [ˈpresɪdəns]:n. 优先,优先权
associativity [ə'səʊʃəˌtɪvɪtɪ]:n. 可结合性,结合体,缔合性

2. Alternative spellings (替代拼写)

C++ specifies alternative spellings for some operators. In C, the alternative spellings are provided as macros in the <iso646.h> header. In C++, these alternatives are keywords, and use of <iso646.h> or the C++ equivalent <ciso646> is deprecated.
C++ 为某些运算符指定了替代拼写。在 C 中,替代拼写在 <iso646.h> 标头中作为宏提供。在 C++ 中,这些替代项是关键字,<iso646.h> 或 C++ 等效的 <ciso646> 已弃用。

3. C++ operator precedence and associativity table (C++ 运算符的优先级和关联性表)

The following table shows the precedence and associativity of C++ operators (from highest to lowest precedence). Operators with the same precedence number have equal precedence unless another relationship is explicitly forced by parentheses.
下表显示 C++ 运算符的优先级和关联性 (从最高优先级到最低优先级)。优先级别编号相同的运算符具有等同的优先级别,除非由括号显式施加另一种关系。

Operator DescriptionOperatorAlternative (替代项)
Group 1 precedence, no associativity (第 1 组优先级,无关联性)
Scope resolution (作用域解析运算符)::
Group 2 precedence, left to right associativity (第 2 组优先级,从左到右关联)
Member selection (object or pointer). or ->
Array subscript (数组下标)[]
Function call (函数调用)()
Postfix increment (后缀递增)++
Postfix decrement (后缀递减)--
Type name (类型名称)typeid
Constant type conversion (常量类型转换)const_cast
Dynamic type conversion (动态类型转换)dynamic_cast
Reinterpreted type conversion (重新解释的类型转换)reinterpret_cast
Static type conversion (静态类型转换)static_cast
Group 3 precedence, right to left associativity (第 3 组优先级,从右到左关联)
Size of object or type (对象或类型的大小)sizeof
Prefix increment (前缀递增)++
Prefix decrement (前缀递减)--
One’s complement (二进制反码)~compl
Logical not (逻辑“非”)!not
Unary negation (一元求反)-
Unary plus (一元加)+
Address-of&
Indirection (间接寻址)*
Create object (创建对象)new
Destroy object (销毁对象)delete
Cast (强制转换)()
Group 4 precedence, left to right associativity (第 4 组优先级,从左到右关联)
Pointer-to-member (objects or pointers).* or ->*
Group 5 precedence, left to right associativity (第 5 组优先级,从左到右关联)
Multiplication (乘法)*
Division (除法)/
Modulus (取模)%
Group 6 precedence, left to right associativity (第 6 组优先级,从左到右关联)
Addition (加法)+
Subtraction (减法)-
Group 7 precedence, left to right associativity (第 7 组优先级,从左到右关联)
Left shift ()<<
Right shift ()>>
Group 8 precedence, left to right associativity (第 8 组优先级,从左到右关联)
Less than (小于)<
Greater than (大于)>
Less than or equal to (小于或等于)<=
Greater than or equal to (大于或等于)>=
Group 9 precedence, left to right associativity (第 9 组优先级,从左到右关联)
Equality (等于)==
Inequality (不相等)!=not_eq
Group 10 precedence left to right associativity (第 10 组优先级,从左到右关联)
Bitwise AND (按位“与”)&bitand
Group 11 precedence, left to right associativity (第 11 组优先级,从左到右关联)
Bitwise exclusive OR (按位“异或”)^xor
Group 12 precedence, left to right associativity (第 12 组优先级,从左到右关联)
Bitwise inclusive OR (按位“与或”)|bitor
Group 13 precedence, left to right associativity (第 13 组优先级,从左到右关联)
Logical AND (逻辑与)&&and
Group 14 precedence, left to right associativity (第 14 组优先级,从左到右关联)
Logical OR (逻辑或)||or
Group 15 precedence, right to left associativity (第 15 组优先级,从右到左关联)
Conditional (条件)? :
Assignment=
Multiplication assignment (乘法赋值)*=
Division assignment (除法赋值)/=
Modulus assignment (取模赋值)%=
Addition assignment (加法赋值)+=
Subtraction assignment (减法赋值)-=
Left-shift assignment (左移赋值)<<=
Right-shift assignment (右移赋值)>>=
Bitwise AND assignment (按位“与”赋值)&=and_eq
Bitwise inclusive OR assignment (按位“与或”赋值)|=or_eq
Bitwise exclusive OR assignment (按位“异或”赋值)^=xor_eq
throw expressionthrow
Group 16 precedence, left to right associativity (第 16 组优先级,从左到右关联)
Comma,

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/
[2] C++ built-in operators, precedence, and associativity, https://learn.microsoft.com/en-us/cpp/cpp/cpp-built-in-operators-precedence-and-associativity

http://www.lryc.cn/news/391684.html

相关文章:

  • 正则表达式替换字符串的方法
  • 开源模型应用落地-FastAPI-助力模型交互-WebSocket篇(五)
  • 2024/7/4总结
  • 【Android面试八股文】Looper如何在子线程中创建?
  • IT项目管理文档体系
  • ELK企业内部日志分析系统(1)
  • 反序列化POP链技术详解
  • process.env.VUE_APP_BASE_API
  • 面试题--SpirngCloud
  • 中位数贪心,3086. 拾起 K 个 1 需要的最少行动次数
  • xml_woarchive undefined symbol
  • SiCat:一款多功能漏洞利用管理与搜索工具
  • 毕业论文初稿写作方法与过程
  • SLAM 精度评估
  • Postman使用教程
  • UDP协议深入解析
  • Rethinking Federated Learning with Domain Shift: A Prototype View
  • 打卡第2天----数组双指针,滑动窗口
  • Running cmake version 2.8.12.2解决方案
  • stm32中IIC通讯协议
  • 允许防火墙通过端口 6379(通常用于 Redis 服务)那些年因为连接失败而一起熬过的夜
  • tsconfig.json的include和exclude作用
  • firewalld(8) policies
  • 为什么进口主食冻干那么高贵?必入榜主食冻干总结分享
  • 状态模式在金融业务中的应用及其框架实现
  • redis学习(002 安装redis和客户端)
  • 在线客服系统多国语言,适合跨境外贸业务对外沟通 ,哈萨克语客服系统,根据浏览器语种标识自动切换...
  • 等保2.0是否强制要求所有物联网设备都必须支持自动更新?
  • gin框架解决跨域问题
  • 4.判断登录用户选择按钮的展示