In reality, you will not need pointers to pointers (2D pointers) to store a matrix, a simple pointer will do, all you need is a mapping function.
Say I want to store a[6][6] in *p, then a[i][j] is *(p+(i*columes)+j)
A real use of pointer to pointer is when you need to exchange the rows in the matrix, or when you have to store array of different lengths and need a same mapping function.
In that case
Code:
int **p;
p = (**int) malloc(sizeof(int *)*ROWS);
for(i=0; i<ROWS; i++)
{
*(p+i) = (*int) calloc(sizeof(int), COLS); // calloc will set all to 0
}
*(*(p+2)+4) = 5; // Same as a[2][4] = 5
Here the mapping function becomes a[i][j] = *(*(p+i)+j)
I have not checked the code as I don't have any C compiler on my desk right now, but I think it is correct. Just try and reply. i hope that was what you wanted.