在“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屋!
查看全文