Can I delete the NULL pointer?

Asked 1 years ago, Updated 1 years ago, 131 views

NULLThe pointer doesn't point at anything, so there's nothing to do with delete Is it safe to delete? Should I check whether it is NULL or not and delete?

c++ memory-management null-pointer delete pointer

2022-09-22 12:57

1 Answers

delete will check it on its own. Checking NULL and delete is double checking, it's useless, and the code gets messy, so don't do it.

The best method for delete is: delete Make one pointer NULL. This will prevent you from delete and prevent memory from being corrupted.


2022-09-22 12:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.