The best way to look at this is by looking at what a 1D array is:
1 2
|
int myArray[3] = {1,2,3};
int *p = myArray;
|
In the previous code,
p
will point to the first element. This will be the memory address. To print out
you need to dereference the pointer,
*p
I believe you understand that much. Now, let's look at a 2D array:
1 2
|
int myArray[2][3] = { {1,2,3}, {4,5,6} };
int *p = myArray[0];
|
p will have the same value as above. It points to the first value. But in this code:
1 2
|
int myArray[2][3] = { {1,2,3}, {4,5,6} };
int *p = myArray;
|
p will point to the first array in the 2D array, that is, it will point to the array {1,2,3}. If you dereference it, it will have a reference to the first element of that array.
I haven't gotten a chance to test it yet, but I believe this code works for what you want it to do:
1 2 3
|
int myArray[2][3] = { {1,2,3}, {4,5,6} };
int *p[2] = myArray;
int *pp = p;
|
pp should now point to the first value, 1, in the 2D array. If you increment that pointer, it should display 1,2,3,4,5,6.
I believe you can even shorten up the code as so:
1 2
|
int myArray[2][3] = { {1,2,3}, {4,5,6} };
int **p = myArray;
|
p should be the same as pp in the previous example.
I hope this helps.