previous | start | next

14. Two Dimensional Dynamic Arrays (2)

Now try the same example, but with a different typedef:

typedef int * blob;
int main()
{
 int n;
 blob *a;

 cout << "How many rows? ";
 cin >> n;        

 a = new blob[n];  // an array of n blob's
 ...
}

  a[ --]-------->[     ]
                 [     ]
                 [     ]
                 [     ]               
                  ....

The type of a is pointer to blob, that is pointer to int *. That is, a is a pointer to a pointer to an int.

It points to the first int an an dynamically created array of n pointers to int's.

Each of these pointers can now be assigned its own array of int's. These will be the rows of the dynamic array!



previous | start | next