增量可堆叠吗? ie x++++;或(x++)++;;
当我和我的朋友准备考试时,我的朋友说x +++;
与x+= 3;
相同,
这是不正确的,但是IS x ++++; < /代码>与
X+= 1;
或IS (X ++)++;
相同?我可以概括吗?即X +++++++++++++++++;
或((((((((((((((((((((((((((((((((((x++++))上一x+= 7;
也许是完全错误的,对于++++++ X;
或++(++(++(++ X))); 等效于
x+= 3;
也应该推广到-X; x;
and x-;
When me and my friend were preparing for exam, my friend said that x+++;
is the same as x+=3;
It is not true but is x++++;
same as x+=1;
or is (x++)++;
? Could I generalize it? I.e. x++++++++++++++;
or ((((((x++)++)++)++)++)++)++;
is equivalent to x+=7;
Maybe it's completely wrong and it is true for ++++++x;
or ++(++(++x));
equivalent to x+=3;
Also it should generalize to --x;
and x--;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用标准的以下规则来理解程序的行为。
来自 lex.pptoken#3.3 :
从 lex.pptoken#5 :
使用上面引用的语句,
x ++++
将被解析为x ++ ++
。但是请注意,从增量/减少/减少操作员的文档:
这意味着
x ++
的结果将 prvalue 。因此,下一个Postfix增量++
不能应用于该prvalue,因为它需要 lvalue 。因此,x ++++
不会编译。同样,您可以使用上述语句来了解摘要中其他示例的行为。
The behavior of your program can be understood using the following rules from the standard.
From lex.pptoken#3.3:
And from lex.pptoken#5:
Using the statement quoted above,
x++++
will be parsed asx++ ++
.But note that from increment/decrement operator's documentation:
That means the result of
x++
will a prvalue. Thus the next postfix increment++
cannot be applied on that prvalue since it requires an lvalue. Hence,x++++
will not compile.Similarly, you can use the above quoted statements to understand the behavior of other examples in your snippet.