Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why C++ delete operator doesn't set pointer to NULL? [duplicate]

Possible Duplicate:
Why doesn't delete set the pointer to NULL?

Is there any purpose for a pointer to deallocated memory?

like image 866
Vanuan Avatar asked Dec 09 '22 13:12

Vanuan


2 Answers

C++ does exactly what you tell it to do. You didn't set the pointer to null, you deleted the memory that the pointer is pointing to.

Why would you waste the extra step of setting it to null (for performance reasons), if you didn't need to?

like image 71
Starkey Avatar answered Dec 12 '22 03:12

Starkey


What if it's a const pointer?

like image 43
Mark Ransom Avatar answered Dec 12 '22 03:12

Mark Ransom