How do we check if a pointer is NULL pointer?

cpuer picture cpuer · May 31, 2011 · Viewed 171k times · Source

I always think simply if(p != NULL){..} will do the job. But after reading this Stack Overflow question, it seems not.

So what's the canonical way to check for NULL pointers after absorbing all discussion in that question which says NULL pointers can have non-zero value?

Answer

cnicutar picture cnicutar · May 31, 2011

I always think simply if(p != NULL){..} will do the job.

It will.