Say you have the following ANSI C code that initializes a multi-dimensional array :
int main() { int i, m = 5, n = 20; int **a = malloc(m * sizeo
Undo exactly what you allocated:
for (i = 0; i < m; i++) { free(a[i]); } free(a);
Note that you must do this in the reverse order from which you originally allocated the memory. If you did free(a) first, then a[i] would be accessing memory after it had been freed, which is undefined behaviour.
free(a)
a[i]