Delete NULL but no compile error

后端 未结 5 1748
悲哀的现实
悲哀的现实 2021-01-18 06:12

I\'m confused why the following C++ code can compile. Why does a call to delete the method of 0 not produce any error?!

int *arr = NULL;     // or if I use 0         


        
5条回答
  •  既然无缘
    2021-01-18 06:48

    The C++ language guarantees that delete p will do nothing if p is equal to NULL.

    For more info, check out Section 16.8,9 here:

提交回复
热议问题