M
Mahendra
I have two cases -
1. When I have a pointer A pointing to a heap memory - What happens when
I dereference the pointer A using free(A).
It deallocated the heap memory the pointer was pointing to. Is that
correct ?
2. If I have a pointer A pointing to a heap memory. Now I create another
pointer B which points to same heap memory as pointer A. But now, I do
not want pointer A to still point to heap memory but I want to remove
the pointer A itself.
In this scenario, if I do not want to deallocate the created heap memory
pointed by pointer A (holding some data in the memory allocated) and
also do not want to copy the memory to some other same struct type, then
is there a way to remove pointer A pointing to heap memory but keep
pointer B pointing to the heap memory.
Essentially my question is - can i deallocate the memory holding the
pointer variable itself ? Can i use free()? If so, can i do it with
free(&p) by freeing the memory which holds the pointer variable itself.
Thanks
Mahendra
1. When I have a pointer A pointing to a heap memory - What happens when
I dereference the pointer A using free(A).
It deallocated the heap memory the pointer was pointing to. Is that
correct ?
2. If I have a pointer A pointing to a heap memory. Now I create another
pointer B which points to same heap memory as pointer A. But now, I do
not want pointer A to still point to heap memory but I want to remove
the pointer A itself.
In this scenario, if I do not want to deallocate the created heap memory
pointed by pointer A (holding some data in the memory allocated) and
also do not want to copy the memory to some other same struct type, then
is there a way to remove pointer A pointing to heap memory but keep
pointer B pointing to the heap memory.
Essentially my question is - can i deallocate the memory holding the
pointer variable itself ? Can i use free()? If so, can i do it with
free(&p) by freeing the memory which holds the pointer variable itself.
Thanks
Mahendra