在C ++中的多个变量preincrement操作(C?) [英] Multiple preincrement operations on a variable in C++(C ?)
本文介绍了在C ++中的多个变量preincrement操作(C?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么下面的编译C ++?
Why does the following compile in C++?
int phew = 53;
++++++++++phew ;
同样的code在C不能,为什么?
The same code fails in C, why?
推荐答案
这是因为 C ++
pre-递增运算符的返回的一个左值
,它需要它的操作数是左值
。
That is because in C++
pre-increment operator returns an lvalue
and it requires its operand to be an lvalue
.
++++++++++唷;
在PTED为间$ P $ +(++(++( ++(++唷))))
不过您code调用未定义行为
,因为你要修改的值唷
不止两人一度之间序列点。
However your code invokes Undefined Behaviour
because you are trying to modify the value of phew
more than once between two sequence points.
在 C
,pre-递增运算符的返回的一个右值
和要求其操作数是一个左值
。所以,你的code没有在C模式下进行编译。
In C
, pre-increment operator returns an rvalue
and requires its operand to be an lvalue
. So your code doesn't compile in C mode.
这篇关于在C ++中的多个变量preincrement操作(C?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文