c - C 编程语言的运算符优先级表

标签 c operator-precedence c11

列出 C 语言中所有运算符的正确运算符优先级表应该是什么样的?

我在网上进行了广泛的搜索,发现了很多这样的优先级表。唉,我还没有找到满足这些要求的一个:

  • 列出 ISO 9899:2011 中定义的 C 语言中的所有 运算符,不混入任何 C++ 运算符。
  • 完整且正确的优先级顺序列出运算符。

最佳答案

enter image description here


解释

Prec. 表示运算符优先级,其中第 1 组的优先级最高,第 17 组的优先级最低。

Assoc. 表示 operator associativity ,在适用的情况下。关联性可以是从左到右或从右到左。

来源

我写这篇文章的目的是在 Stack Overflow 现场提供一个正确且规范的运算符优先级表。这个运算符优先级表直接对应于ISO 9899:2011的第6.5章,我们可以在其中阅读(6.5/3):

The grouping of operators and operands is indicated by the syntax. 85)

然后作为注释,在信息性(非规范性)脚注中:

85) The syntax specifies the precedence of operators in the evaluation of an expression, which is the same as the order of the major subclauses of this subclause, highest precedence first. /--/

Within each major subclause, the operators have the same precedence. Left- or right-associativity is indicated in each subclause by the syntax for the expressions discussed therein.

表中的所有正式运算符名称均取自第 6.5 章,在规范文本中可以找到此类名称。在程序员社区可能比标准中给出的名称更熟悉另一个名称的情况下,会包含非正式名称。

关于c - C 编程语言的运算符优先级表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17369090/

相关文章:

c - 退出函数的 noreturn 属性是否必要?

幂函数的C实现

c - 如何为不断增加的文件连续生成名称?例如: book1. txt、book2.txt等

c++ - 为什么 string::append 操作表现奇怪?

c - 为什么这些构造使用增量前和增量后未定义的行为?

c - 匿名联盟的目的是什么?

c - 如何用C语言将两个字符串写入一个文件并对其进行排序?

c - I/O 多路复用中的写入 block 如何?

mysql - 在mysql中执行find_in_set()

c - 第 5.1.2.3 节第 4 段(在 n1570.pdf 中)对空操作意味着什么?