列出 C 语言中所有运算符的正确运算符优先级表应该是什么样的?
我在网上进行了广泛的搜索,发现了很多这样的优先级表。唉,我还没有找到满足这些要求的一个:
- 列出 ISO 9899:2011 中定义的 C 语言中的所有 运算符,不混入任何 C++ 运算符。
- 以完整且正确的优先级顺序列出运算符。
最佳答案
解释
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/