我是 Java 新手。
刚发现在表达中,
y=x++
,y取x的值,x变为+1。
如果我听起来很愚蠢,请原谅我,但根据 order of precedence ,赋值运算符在最后。所以 x++ 不应该首先发生然后是分配。提前致谢。
最佳答案
Q: So isn't
x++
supposed to happen first followed by the assignment.
答:是的。这就是发生的事情。语句 y = x++;
等效于以下内容:
temp = x; // | This is 'x++'
x = x + 1; // | (note that 'temp' contains the value of 'x++')
y = temp; // This is the assignment.
但是如您所见,操作顺序(++
和 =
)不会影响操作的实际作用。
因此……
Q: How are
y=x++
andy=x--
different when the assignment operators has the least priority?
答:他们不是。
关于java - 当赋值运算符的优先级最低时,y=x++ 和 y=x-- 有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67946625/