Possible Duplicate:
Why doesn't delete set the pointer to NULL?
Is there any purpose for a pointer to deallocated memory?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, there’s no real use to leaving it set to the original value, other than showing how inept people are at writing code 🙂
It follows the traditions of C in that you’re expected to know what you’re doing. The cost of having the compiler set freed pointers to NULL was deemed too high in the C days and this has carried over to C++ with
delete. If you code properly, then having the compiler set the pointer to NULL is a waste, since you’ll either set it to something else or not use it again.If you really want to make your code safer, you’d do something like (in C):
instead of just:
But, if you’re going to go to that level (and introduce such an abomination), just switch to Java and be done with it, then you don’t have to concern yourself with manual memory management at all.