+ 9

free dynamic allocation

how to know if this memory is freed in c ex: int *p=malloc(sizeof(int)); free(p); after that how to know if this memory is freed

23rd May 2019, 10:47 AM
ABADA S
ABADA S - avatar
2 Respostas
+ 6
its definitely free, but if you have a doubt, just use an if statement to check if the value of the pointer is NULL then the memory is freed, i guess you know how to do that edit: am not sure they is a way to check this, but after freeing the pointer you can assign the pointer to NULL
23rd May 2019, 11:14 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 2
p will not be null after free call because I pass p by value so p will not affected
23rd May 2019, 11:22 AM
ABADA S
ABADA S - avatar