The code below is a condensed version of a code extract from a book, the idea was to create a copy of the ptr variable, then have the ptr variable point to a different address and finally delete the temporary pointer.
If my understanding is correct, does calling delete on the temporary pointer actually delete the original num variable? And since both the temporary pointer and num are dangling pointers is it correct to set them both to NULL?
int *num = new int(5); int num1 = 10; int *ptr = num; int *temp = ptr; ptr = &num1; delete temp; temp = NULL; num = NULL;
deletedeletes the object being pointed to (it's not a reference-counted release based on the pointer, or anything like that)