Results 1 to 2 of 2
  1. #1
    csanch11 is offline Member
    Join Date
    Oct 2013
    Posts
    63
    Rep Power
    0

    Default Drawing memory of address

    I just wanted to know if my understanding of array is correct. Here you have some code and I try to draw a picture of memory. Is this correct?

    int[ ] m = new int[2];
    m[0] = 0;
    m[1] = 1;
    int[ ] p = m;
    p[0] = 4;
    p[0] = 5

    **My attempt in “drawing a picture of memory”**
    m ---> [empty][empty]
    m ---> [0][empty]
    m ---> [0][1]
    p=m ---> [0][1] **Here, array variable p references array variable m. Both are referencing the same address. Whatever changes happens in array p will also happen in array m.
    p ---> [4][1] and m ---> [4][1]
    p ---> [4][5] and m ---> [4][5]

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Drawing memory of address

    That's pretty much correct. In the latter two lines it would be clearer (imho) to show two separate lines, one from p and one from m, pointing to a single memory location containing the values. These types of diagrams are much easier to do using slide preparations tools (e.g.PowerPoint).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 3
    Last Post: 11-04-2013, 12:53 AM
  2. Replies: 2
    Last Post: 08-20-2012, 06:38 PM
  3. Replies: 1
    Last Post: 07-18-2011, 04:24 PM
  4. Replies: 2
    Last Post: 08-21-2008, 07:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •