Page 1 of 1

[C++] Ce se intampla daca dam delete la un pointer NULL?

Posted: 30 Jan 2009, 13:02
by Ovidiu Cucu
Intrebare: Ce se intampla daca dam delete la un pointer NULL?
Raspuns: Nu se intampla nimic.

NOTA: Teste gen

Code: Select all

    if(p != 0)
    {
        delete p;
    }
in cele mai multe cazuri nu fac decat sa complice codul.
Standardul de C++ spune urmatoarele:
...if the value of the operand of delete is the null pointer the operation has no effect.
Deci, testul de NULL dinaintea lui delete, nu are rost.

Resurse
  • ISO/IEC 14882:2003 - 5.3.5 Delete


Next FAQ >>