+= 和 =+ 的区别 [英] The difference between += and =+
本文介绍了+= 和 =+ 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我多次将 +=
与 =+
放在一起,我想我一直忘记,因为我不知道这两者之间的区别,只是一个给了我我期望的价值,而另一个没有.
I've misplaced +=
with =+
one too many times, and I think I keep forgetting because I don't know the difference between these two, only that one gives me the value I expect it to, and the other does not.
这是为什么?
推荐答案
a += b
是 a = a + b
的简写(但请注意表达式 a
只会被评估一次.)
a += b
is short-hand for a = a + b
(though note that the expression a
will only be evaluated once.)
a =+ b
就是a = (+b)
,即赋值b
的一元+
a
.
a =+ b
is a = (+b)
, i.e. assigning the unary +
of b
to a
.
示例:
int a = 15;
int b = -5;
a += b; // a is now 10
a =+ b; // a is now -5
这篇关于+= 和 =+ 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文