07
Dec
Do I need to check for NULL before delete?
Related Blog Items
- What are the two steps that happen when I say delete p?
- Double Linked List With Out Using Special Head or Tail Node
- Binary Search Trees
- Does delete delete the pointer, or the pointed-to-data?
- Balanced (AVL) Binary Search Trees
No!
The C++ language guarantees that delete p will do nothing if p is equal to NULL. Since you might get the test backwards, and since most testing methodologies force you to explicitly test every branch point, you should not put in the redundant if test.
Wrong:
if (p != NULL)
delete p;
delete p;
Right:
delete p;
source: USENET
[tags] NULL check before delete[/tags]
Popularity: 5%
You need to log on to convert this article into PDF
Related Blog Items - What are the two steps that happen when I say delete p?
- Double Linked List With Out Using Special Head or Tail Node
- Binary Search Trees
- Does delete delete the pointer, or the pointed-to-data?
- Balanced (AVL) Binary Search Trees
Related Blog Items
- What are the two steps that happen when I say delete p?
- Double Linked List With Out Using Special Head or Tail Node
- Binary Search Trees
- Does delete delete the pointer, or the pointed-to-data?
- Balanced (AVL) Binary Search Trees
No Comments
No comments yet.