这里有几个迷题,希望有哪位大虾能帮忙解答下。1、对于“int a=3;a+=a-=a*a;”,a的结果为-3,并不是-12。为什么呢?
2、对于“int i=10;i=i++;”,i的值是10,并不是11。为什么呢?
3、对于“int x=2,y=3;x=y+(y=x)*0;”,x的值为3,y的值为2。这个结果是怎么得出的呢?
2、对于“int i=10;i=i++;”,i的值是10,并不是11。为什么呢?
3、对于“int x=2,y=3;x=y+(y=x)*0;”,x的值为3,y的值为2。这个结果是怎么得出的呢?
= += -= *= 从右到左
2.至于i++问题。
具体实现应该是这样:
int temp;
temp = i;
i = i+1;
return temp;
3.说不准
1.
a+=a-=a*a
a=a+(a=a-a*a)
a=3+(a=3-9)
a=3+(a=-6)
a=3+(-6)
a=-32.
i=i++;
i=i;
i=10;
(- -!!!)3.
x=y+(y=x)*0
x=3+(y=2)*0
x=3+2*0 //此时y为2
x=3
//此时x为3
chenchengamao
(see¤sea) 等 级:
结帖率:109.09% 楼主怎么结贴的???
i = i++; //10
i = i--; //10
i = ++i; //11
i = --i; //9
2. x = x+y; y = x-y; x = x-y;
3. x = x-y; y = y+x; x = y-x;
4. x = y-x; y = y-x; x = x+y;
istore [a]//a+=a-=a*a
//先加载4个a的值到栈中
iload [a]
iload [a]
iload [a]
iload [a]//a=3-3*3
imul
idec
istore [a] //存入a的值为-6//a=3+(-6)
iadd
istore [a] //存入a的值为-3所以最终结果为-3
bipush 10
istore [i]//i=i++
iload [i]
istore [i] //寸入10
iinc [i] 1 //变量i自加1
iconst_2
istore [x]
iconst_3
istore [x]//x=y+(y=x)*0
iload [y] //进栈,3
iload [x] //进栈,2
istore [y] //把2存入y,2退栈
iload [y] //进栈,2
iconst_0 //进栈,0
imul //2*0,0退栈,2退栈,结果为0进栈
iadd //3+0,0退栈,3退栈,结果为3进栈
istore [x] //3存入x,3退栈