后增量行为 [英] post increment behaviour
本文介绍了后增量行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一点疑问。为什么下面的代码是打印值i = 2.
i have small doubt.why the below code is printing value i=2.
int i=2;
i=i++;
System.out.println(i);
有人可以向我解释第2行的情况。
can someone please explain me what is happening in line no 2.
所以在这里做++没有任何意义吗?
so there is no meaning here of doing ++ here?
谢谢
推荐答案
i=i++;
因为首先发生了分配,所以增量适用。
Because first the assignment happens, then the increment applies.
类似的东西:
首先我得到2,然后++操作发生,但结果不会重新分配给i,所以我会重视保持为2。
first i gets 2, then ++ operation happens, but results won't be re-assigned to i, so i value will remain as 2.
这篇关于后增量行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文