Page 2 of 2 First 12
  • Jump to page:
    #16
  1. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    Originally posted by 7stud
    lol. Not really. I understand what the notation represents(see the previous couple of posts and the original thread), I was wondering about what happens internally in memory. However, the second part of the post was very helpful--thanks.
    Ok, let me try again. I am guessing at what exactly you are referring to when you say "what happens internally in memory" - I assume you mean during pointer operations, since the pointer itself is just a 32-bit address no matter what it points to (on a win32 system, anyway). If you mean something else by this, let me know. Also, I apologize if I state the obvious below, but the best way to explain this is to get down to the basics.

    Originally posted by 7stud
    If you want a pointer to a basic type to jump to the next row, it won't work. A pointer declared like this:

    int* pint;

    won't do what you want.
    Basically, the compiler remembers what type the pointer is pointing to, so it knows its size. In fact, the size is all that matters. If you have a byte, pbyte++ will increment it by 1. If it points to a long, then plong++ increments it (the 32-bit address) by 4.

    Originally posted by 7stud
    Also, I'm not sure about the internals of this:

    int (*pArr2d)[3] = Arr2d;

    and how it works. The one thing I noticed is that you can say:

    pArr2d[0]

    which doesn't make sense to me, since pArr2d is not supposed to be an array of pointers like when declaring it this way:

    int* pArr2d[3];
    int (*pArr2d)[3] = Arr2d;

    is a declaration and initialization at the same time. So let's break it down to make it simplier:

    int (*pArr2d)[3]; // this makes pArr2d a pointer to type X (X = arrray of 3 ints)
    pArr2d = Arr2d; // set the address of pArr2d to the address of Arr2d, duh.

    pArr2d[0] is using a pointer in array-style accessing. Take a look at this first:

    int *pint;
    int array[10] = {0,1,2,3,4,5,6,7,8,9};
    pint = array; // pint = &array[0];
    pint[5] accesses the 6th value in array[]. To the compiler, it is exactly the same as array[5], or *(pint+5), or *(array+5). They are all the same, since pointers and arrays are the same.
    This is why pint = array works, and you don't need to use pint = &array[0] syntax.

    Okay, going back to:

    pArr2d[0]

    It is accessing the 1st element of Arr2d, which is the first X in the array. What is the first X? X is an array of 3 ints, so the first X is the first array of 3 ints - otherwise, the first 'row' of the 2D array.

    I hope that explanation helps...
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,473
    Rep Power
    15
    Sorry, I didn't mean I didn't understand. I got it the first time. Thanks.
  4. #18
  5. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo