Home > Back-end >  Why do I=0?
Why do I=0?

Time:01-02

` ` Java
Package com. Atguigu. Test06;

Public class Test06 {
Public static void main (String [] args) {
int i=0;
Change (I);
I=i++;
System. The out. Println (" I="+ I);
}
Public static void change (int I) {
i++;
}
}

` ` `
Why I added twice, the operation result is equal to zero, instead of 2?

CodePudding user response:

I just in change function value, is not going to change in the main I
And I=i++, when I into the stack at the moment I=0, then execute iinc instructions, to accumulate after I I=1, finally I stack, before this I was pressed into the bottom of the stack of I so finally I=0
I=i++ is a friendly way, meet cranky could hammer you a meal, if you want to direct i++ + + or + + I went to I=I + 1 is a reasonable
  • Related