+ 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

4th Feb 2020, 6:41 AM
Carlos Caminero
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;
4th Feb 2020, 7:16 AM
āœ³AsterisKāœ³
āœ³AsterisKāœ³ - avatar