+ 3

I do not understand how to free memory?

if the location that a pointer (p) points to in the heap memory is freed using another pointer (q) , what is the pointer pointing to deallocated memory called? realloc , free

11th Apr 2021, 1:05 PM
Aid
Aid - avatar
2 Answers
+ 6
In c, you'd use the free function. free corresponds with c's malloc or calloc functions. In c++, you'd use the delete keyword. delete corresponds with c++'s "new" keyword. A pointer holding the address of a freed block of memory doesn't have a special name that I'm aware of. I would set it to NULL as soon as possible, though. NULL clearly indicates that it doesn't point to an allocated block of memory. Any other value often means something is accessible so you're more at risk for a segmentation fault, memory access violation, or other buggy behaviour by maintaining a non-NULL pointer to a freed block of memory.
11th Apr 2021, 2:23 PM
Josh Greig
Josh Greig - avatar
+ 3
I dont think, there is an official name for it. But it is often called "dangling Pointer".
11th Apr 2021, 2:27 PM
G B
G B - avatar