+ 1
If I have a pointer pointing to another pointer (both created with the function Malloc()). How can I free the memory?
Pointers in C
1 Answer
0
just like ćļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć to help you don't have to "it's unnecessary to allocate memory for a pointer that will just point to another allocated memory pointer" but you can still do this
int *ptr1 = malloc(sizeof(int) *3);
int *ptr2 = ptr1;
then you can free ptr1 from ptr2 since they both point to the same address
free(ptr2);
ptr2=NULL;