2D arrays:dynamic allocation and freeing
The way to dynamically allocate a 2D array is :
This will create array of pointer to arrays.
We can access elements as a 2D array
a with access particular element.
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.
Is my way of freeing ok
Because it will free the pointers , what about the elements associated with those pointers.
where have i found int (*);
Sorry for that message above:
This is valid syntax.
Actually, i was going through code for mp3, at that time i found this:
unsigned char (*main_data)[MAD_BUFFER_MDLEN];
struct mad_stream *stream;
stream->main_data=(unsigned char (*)[MAD_BUFFER_MDLEN])malloc(MAD_BUFFER_MDLEN);
And this alloates pointers to array of characters i.e. strings.
In this array lots of strings can be stored.
Am I wrong with the above statement?
If yes, do correct me.