+ =和= +之间的差异
问题描述:
我错了+ = = = +一次多次,我想我一直都忘了因为我不知道这两者之间的区别,只有那一个给了我期望它的价值,而另一个没有。
I've misplaced += with =+ one to 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