previous | start | next

13. Two Dimensional Dynamic Arrays (1)

Two see how to create a dynamic two dimensional array (i.e., specify the number of rows and columns during execution), first look again at creating a 1-dimensional dynamic array.

The typedef declaration gives a name to an existing type.

 typedef int blob;
     

This defines blob to be an alias for the type int.

Create a 1-dimensional array of blob's

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.

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



previous | start | next