valid or invalid pointer

Hello Forum,

How do we distinguish between the valid and invalid pointer ?

Check the following code
1
2
3
4
5
6
7
void func(int *i)
{
   if(i)
   {
       // does it mean that i is valid 
   }
}


So if we check for if(i != NULL) , does it mean that the pointer is valid ?

Any thoughts ?


Regards
Sajjadul
So if we check for if(i != NULL) , does it mean that the pointer is valid ?


No. It means the pointer is not NULL. In general, there is no way to check if a pointer is "valid" so you should avoid situations where you have invalid pointers hanging around.
Semantically, the null pointer is the only pointer that with certainty is always "valid". Not the "safe to dereference" kind of valid though.
Topic archived. No new replies allowed.