Re: How to free dynamically allocated array?




Markus wrote:
> Hi,
>
> I have read the FAQ 6.16 on how to dynamically allocate a
> two-dimensional array.
>
> I do it like this:
>
> double** A = (double **)malloc(m * sizeof(double *));
> for(i = 0; i < m; i++)
> A[i] = (double *)malloc(n * sizeof(double));
>
> But how do I free it? I currently have only
>
> free(A);
>
> but I guess it is not enough.
>
> The FAQ is not clear about this.
>

for(i = 0; i < m; i++)
free(A[i]);
free(A);

Krishanu

.



Relevant Pages