C语言 n=1,表达式n+++n---n结果是多少

如题所述

显然是1,原式可以看成(n++)+(n--)-n,++和--都在+和-运行后运行且影响n的值,不影响表达式值,所以表达式值为1+1-1=1
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-01-28
n+++n
=>(n++)+n;这里先算n+n的值是2,然后n自加1后n=2;
---n这里,先算--n,这时n的值为1,然后就是2-1=1,就是结果
第2个回答  2010-01-17
ISO/IEC 14882:2003(E) 中 2.3 写到:
3, 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, even if that would cause further lexical analysis to fail.
。。。
5, [Example: The program fragment x+++++y is parsed as x ++ ++ + y, which, if x and y are of built-in types, violates a constraint on increment operators, even though the parse x ++ + ++ y might yield a correct expression. ]
也就是说词法分析中,在一个简单的从左到右的扫描中的每个点,最长的的记号被划分,不管这样出来的记号是否有意义,所以你这个表达式会被解释成
n++ + n-- - n
但这样的表达式的结果仍是未定义的,因为在一个序列点结束之前两次改变了 n 的值,也即 n++ + n-- 这个表达式的行为是未定义的 ,所以无法根据标准计算出你这个表达式的结果,要依具体实现而定,如果在你的编译器上它的执行结果是 1 ,那你就可以暂时认为它是 1
第3个回答  2010-01-17
用编译器运行后得 1 , 和xpressa说的一样
第4个回答  2010-01-16
你可以找编译软件运行一下。。