|
最初由 dm071 发布
[B]你的第一问题是java 有bug. k=k++,java实际没有对k进行加1计算.
第二个问题是y=k++,编译器先把k赋值给y,然后对k加1.这个语句,java编译器没产生问题. [/B]
Sorry, I don't think so! Java has no bug on this computation. See below explanation:
k = k++;
First compute k++ computation. the expression returns 0 but k is 1. And next assign the result to k. so k is 0, not 1. check the detail computing steps:
1. Do compute k++, the result is 0 because k++ is a post++ computation.
2. k increase itself after giving result 0. So now k is 1.
3. Finally, do the assignment. Give the result 0 the k. So k is 0 now, not 1!
And how about i = 2; i = (++i) + (i++) ? Please see the below steps! You can get it clear to yourself.
1. i++ has precedence, so the right side will increase i to 3, but returns 2. The left will increase i from 3 to 4. So the equation actually looks like i = 4 + 2, and get 6. |
|