“x = x++"之后的 x 是什么? [英] What is x after "x = x++"?
本文介绍了“x = x++"之后的 x 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
执行此操作时(幕后)会发生什么?
What happens (behind the curtains) when this is executed?
int x = 7;
x = x++;
也就是说,当一个变量在一个语句中被后递增并赋值给它自己时?我编译并执行了这个.x
仍然是 7 即使在整个语句之后.在我的书中,它说 x
是递增的!
That is, when a variable is post incremented and assigned to itself in one statement? I compiled and executed this. x
is still 7 even after the entire statement. In my book, it says that x
is incremented!
推荐答案
x
确实增加了.但是您正在将 x
的旧值分配回自身.
x
does get incremented. But you are assigning the old value of x
back into itself.
x = x++;
x++
递增x
并返回其旧值.x =
将旧值分配回自身.
x++
incrementsx
and returns its old value.x =
assigns the old value back to itself.
所以最后,x
被赋值回它的初始值.
So in the end, x
gets assigned back to its initial value.
这篇关于“x = x++"之后的 x 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文