A one-dimensional array is a two-dimensional array, similar to an array. We define a two-dimensional array with int[] []arr=new int[m][n], similar to one-dimensional, which is stored in heap memory and accessed as an address, such as: Traversing a two-dimensional array uses two for loops, which are about the same as C
After learning the array, I started to understand the memory mechanism of Java, and then the main problem was parameter passing. Let me give you an example. In main we define an int a=0;int b=1;r and then we construct a function change to test, the specific change is:
void change (int a,int b) {
a++;
B + +;
}
What happens if I add it to the main function? The answer is not a=1,b=2, in fact, the main function in the int a=0;int b=1, in the stack open an area, save the information, and in the change method when the change of int a,int B will open up a zone in the stack to hold the two A, B, That is, the change inside the A.B is not the same in the main function, then if we do in the action is not to affect the main function of a, a, that is, if we output a B then the result is 0 1.
To summarize, once the method inside the call is the address of a class, then its change will affect the original, and conversely if it is defined in the stack, then it just in the stack itself opened up a region, does not affect the original value.
5th Day of Java Learning