I did not find the tutorial on dynamic arrays, so I'm posting up a sample program that uses one 2D array.
It doesn't use realloc(), but that is something I very seldom need to use.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
int **mat; // Pointer to pointer
int rows, cols, i, j;
printf("How many rows you want ");
scanf("%d", &rows);
//rows = 10;
//cols = 10;
mat = malloc(rows*sizeof(int*)); // array of number of rows
printf("How many cols ");
scanf("%d", &cols);
for (i=0; i<rows; i++) { // for each row ...
mat[i] = malloc(cols * sizeof(int)); // add these many cols
}
for (i = 0; i<rows; i++) {
for (j = 0; j<cols; j++) {
mat[i][j] = (i+1) * (j+1);
printf("%4d ", mat[i][j]); //these two print lines
//printf("%4d ", *(*(mat+i)+j)); //do the same thing
}
putchar('\n');
}
printf("\n\n");
return 0;
}