How to free memory in this program
Hi all,
I have a hard time to determine where I appropriately free the allocated memory on the heap for 2Dim array below:
Code:
int main()
{
int **TwoDimPtr;
TwoDimPtr = Create2DimArr(ROW, COL);
/* Do some processing with 2D array here and then free its memory*/
/* free the allocated memory here?? */
free Creat2DimArr(ROW, COL);
return 1;
}
int **Create2DimArr(row, col)
{
int r;
int **twoDimArr = malloc(row * sizeof(int *));
for (r=0; r<row; r++)
twoDimArr[r] = malloc(col * sizeof(int));
return twoDimArr;
/* and reclaim memory from the heap here, right? */
free(twoDimArr);
}
Your help would highly respected and appreciated.
Coconut