I prepared this simple program in hopes that it will help explain pointers to a 2nd semester C++ programming class. Do you see anything inaccurate or particularly confusing in any of my comments?
I'm a little worried about this line in particular:
Code:
// It also stores an int** pointer to the 2-d array itself,
// which holds the beginning address of the block of
// int* pointers.
Anything wrong with that?
Thanks for looking.
Code:
#include <iostream>
using namespace std;
int main () {
int i,j;
int iarr[4][2] = {{1,2},{3,4},{5,6},{7,8}};
// When we declare a 2-dimensional int array, the compiler:
// allocates a contiguous block of memory in which to
// store the requested number of ints.
// It also allocates another contiguous block of memory // NO
// in which it stores int* pointers to the 1-dimensional
// arrays representing the "rows" (the last dimension)
// of the int array.
// It also stores an int** pointer to the 2-d array itself, // NO
// which holds the beginning address of the block of
// int* pointers.
// code deleted ...
return 0;
}