你可以在同一个变量增量器和一个decrementor在相同c声明 [英] Can you have a incrementor and a decrementor on the same variable in the same statement in c
问题描述
是
--foo++;
在C有效的语句? (将它编译/运行),并没有任何实际应用此?
a valid statement in C? (Will it compile/run) And is there any practical application for this?
对不起,在编辑修改问题,但我发现一些东西。
Sorry for changing the question in an edit but I found something out.
据我的C ++编译器(Visual Studio 2010中):
According to my C++ compiler (Visual Studio 2010):
--++foo;
是一个有效的命令,但
is a valid command but
foo--++;
不是。有没有道理呢?
is not. Is there any reason for this?
推荐答案
没有,它是无效的,因为递增/递减运算符的结果不是左值。
No, it is not valid because the result of the increment / decrement operators is not a lvalue.
编辑:的OP通过增加两个例子编辑他的问题。所以在这里,我们走了,因为同样的原因:
the OP edited his question by adding two more examples . So here we go, for the same reason:
--++foo;
--foo++;
foo--++;
均无效前pression语句,因为递增/递减操作的结果不是左值。编译器可以扩展的语言和接受这些前pressions,但是严格符合程序不能包含任何这些前pressions的。
are all invalid expression statements because the result of increment / decrement operators is not a lvalue. A compiler could extend the language and accepts these expressions, but a strictly conforming program cannot contain any of these expressions.
这篇关于你可以在同一个变量增量器和一个decrementor在相同c声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!