gpt4 book ai didi

c - C中表达式的解析规则是什么?

转载 作者:太空狗 更新时间:2023-10-29 15:22:52 24 4
gpt4 key购买 nike

我怎样才能理解像这样的表达式的解析

a = b+++++b---c--;

在 C 中?

我只是组成了上面的表达式,是的,我可以使用任何编译器检查结果,但我想知道的是基本规则,我应该知道这些规则才能理解此类的解析C 中的表达式。

最佳答案

来自标准 6.2(4):

If the input stream has been parsed into preprocessing tokens up to a given character, the next preprocessing token is the longest sequence of characters that could constitute a preprocessing token.

他们甚至添加了示例:

EXAMPLE 2 The program fragment x+++++y is parsed as x ++ ++ + y, which violates a constraint on increment operators, even though the parse x ++ + ++ y might yield a correct expression.

所以你的声明:

a = b+++++b---c--; 

相当于:

a = b ++ ++ + b -- - c -- ;

关于c - C中表达式的解析规则是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4005076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com