I have small piece of code:
#include <iostream>
using namespace std;
int main()
{
int *p = new int(10);
if(p != NULL)
{
cout<<"Deleted dynamic allocated memory"<<endl;
delete p;
}
if(p == NULL)
{
cout<<"NULL"<<endl;
}
else
{
cout<<"Not NULL"<<endl;
}
return 0;
}
After deleting dynamic allocated memory using delete
operator, Why compilers do not assigned NULL to pointer(like p = NULL) automatically?
delete p+1
. In this case, you cannot set anything tonullptr
. – Adeladelete p
setp
to0
just feeds this misunderstanding. – Obstreperous