Hi,
I learned that deleting memory that has not been allocated will cause segment fault. e.g.
.Code:int main ()
{
int * p;
delete p;
}
However, I have seen in someone's code that
It seems work fine.Code:int main ()
{
int * p = 0;
delete p;
}
Is the second one legal? Does this mean that the memory at address 0 is somehow special?
How to check if a memory has been allocated before deleting it?
Thanks and regards!