when "delete" erase p pointer, it is assumed that p is null, but when the "if" is running, the condition becomes false, if p is null, the condition must be fulfilled(you know true!!)
another problem:
1 2 3 4 5 6 7 8 9 10 11
int *p = newint[100];
delete[] p;
p = NULL;//---> now enabled
if(!p)
{
cerr<<"ERROR";
}
oohhh yeah is workeing, BUTTT WHYYYYYY!!??
and another:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int *p = newint[100];
delete[] p;
p = NULL;//----> Now enable
if(!p)
{
cerr<<"ERROR";
}
delete[] p; //this should not be happened, but it is happening and it is not a error
Please tell me what Can I do...
the real code must be:
1 2 3 4 5 6 7 8 9 10
int *p = newint[100];
delete[] p;
if(!p)
{
cerr<<"Im here yeah, problem solved";
exit(1);
}
cout<<"hey what the hell LOL"<<endl;
then, how can I know if a variable is null or not null, I mean, if a variable (p in this case), is deleted or not deleted, How Can I know that, the only method is comparing with null or there is another method??
how can I know if [...] a variable (p in this case), is deleted or not deleted,
You wrote the program, didn't you? You can know that the same way you know if an integer variable is initialized or not initialized. In modern C++, delete isn't used much anyway, since we have containers and smart pointers.