Code:
----------------------------
dynamically allocated memory||
----------------------------
^
|
|
stackPtr NULL or 0
_______________
other memory /
______________/
stackPtr = &of_something_else;
Code:
----------------------------
dynamically allocated memory||
----------------------------
stackPtr NULL or 0
|
|
\/
________________
other memory /
_______________/
stackPtr = 0;
Code:
----------------------------
dynamically allocated memory||
----------------------------
stackPtr ---------------------> NULL or 0
________________
other memory /
_______________/
delete [] stackPtr;
That line doesn't delete the dynamically allocated memory. Remember when you delete a pointer, you are deleting the memory it points to *NOT* the pointer itself. So, it doesn't matter what pointer you delete as long as the pointer is pointing to the dynamically allocated memory. The goal is to delete the dynamically allocated memory not a certain pointer.