+ =和= +之间的差异 [英] The difference between += and =+

查看:116
本文介绍了+ =和= +之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我错了+ = = = +一次多次,我想我一直都忘了因为我不知道这两者之间的区别,只有那一个给了我期望它的价值,而另一个没有。

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

这篇关于+ =和= +之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆