How to destroy an pointer? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to destroy an pointer?

26th Dec 2016, 12:43 AM
Elegis Sossou
Elegis Sossou - avatar
4 Answers
+ 2
It should be the other way round because you would reallocate your pointer and delete nothing which does not free the space you saved for p. In my way you dislocate the memory, which frees it then you reset the address stored in the pointer.
26th Dec 2016, 12:52 AM
Andreas K
Andreas K - avatar
+ 2
understand
26th Dec 2016, 12:55 AM
Elegis Sossou
Elegis Sossou - avatar
+ 1
The code is delete pointerName; pointername = NULL;
26th Dec 2016, 12:46 AM
Andreas K
Andreas K - avatar
+ 1
So int *p = NULL; delete p;
26th Dec 2016, 12:49 AM
Elegis Sossou
Elegis Sossou - avatar