I have this in my code:
double** desc = new double* [size_out];
for (int i = 0; i < size_out; i++)
desc[i] = new double [size_in];
How do I delete this desc
?
Should I do:
delete [] desc;
or
for (int i=0; i<size_out; i++)
delete [] desc[i];
delete [] desc;
or
for (int i=0; i<size_out; i++)
delete [] desc[i];
delete desc;
?
Simple rules to follow:
new
should be freed using delete
, using new[]
should be deallocated using delete[]
and using malloc
should be deallocated using free
(ex3 is therefore wrong)Conclusion, ex2 is OK.