I did a test on a online compiler(online compiler) with the below code.
#include <iostream>
using namespace std;
int main()
{
int * a = nullptr;
delete a;
return 0;
}
The program compiles and runs with no problem. So it is safe to delete pointer too a nullptr. However, you can not execute delete nullptr;
directly since nullptr is a pointer literal.
No comments:
Post a Comment