I wrote a little test to check for null pointer, I simplified it with int and 0, 1, instead of real classes, what I'm trying to test is something like this: return p ? 1 : 0;
which in real world would be return p ? p->callmethod() : 0;
bool TestTrueFalse();
void main()
{
int i = TestTrueFalse();
}
bool TestTrueFalse()
{
int one = 1;
int * p =&one;
*p = 0;
return p ? 1 : 0;
}
now, you can see, that once the pointer becomes 0 again, the test fails, why? what's wrong with this? what's the solution?