int main(void)
{
int **rptr;
int *aptr;
int *testptr;
int k;
int nrows = 5; /* Both nrows and ncols could be evaluated */
int ncols = 10; /* or read in at run time */
int row, col;
/* we now allocate the memory for the array */
aptr = malloc(nrows * ncols * sizeof(int *));
if(aptr == NULL)
{
puts("\nFailure to allocate room for the array");
exit(0);
}
/* next we allocate room for the pointers to the rows */
rptr = malloc(nrows * sizeof(int *));
if(rptr == NULL)
{
puts("\nFailure to allocate room for pointers");
exit(0);
}
/* and now we 'point' the pointers */
clrscr();
for(k = 0; k < nrows; k++)
{
rptr[k] = aptr + (k * ncols);
}
printf("\n\n\nIndex Pointer(hex) Pointer(dec) Diff.(dec)");