hi all,

The way to dynamically allocate a 2D array is :


int a(*)[5];

a=(int (*)[5])malloc(sizeof(int)*5);


This will create array of pointer to arrays.

We can access elements as a 2D array
a[1][1] with access particular element.



Question:
1.
After allocating space for pointers, is it not the case that i need to allocate space for the array they are pointing to?, as we usually do for a pointer to point to array of elements.

2.
Is my way of freeing ok

for(i=0;i<5;i++)
free(a[i]);

Because it will free the pointers , what about the elements associated with those pointers.