C - Pointer NULL Pointer

Introduction

Suppose that you create a pointer like this:

int *pvalue = NULL;

NULL is a special symbol in C that represents the pointer equivalent to 0.

The symbol is often defined as ((void*)0).

When you assign 0 to a pointer, it's the equivalent of setting it to NULL, so you could write the following:

int *pvalue = 0;

Since NULL is the equivalent of zero, to test whether pvalue is NULL, you can write this:

if(!pvalue)
{
  //the pointer is NULL!
}

When pvalue is NULL, !pvalue will be true. Alternatively, you can write the test as follows:

if(pvalue == NULL)
{
  // Tell everyone! - the pointer is NULL! . . .
}