A surprise from C++

A surprise from C++
http://faqs.cs.uu.nl/na-dir/C++-faq/part08.html
[16.7] Do I need to check for NULL before delete p?

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;

Right:

 delete p;

你可能感兴趣的:(A surprise from C++)