5th Day of Java Learning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.