Site hosted by Build your free website today!

The C Programming Language: NULL

The C language definition states that for each pointer type, there is a special value - the null pointer - that is distinguishable from all other pointer values and that is "guaranteed to compare unequal to a pointer to any object or function".  In other words, it's an invalid address.

Each pointer type has a null pointer, and the internal values of null pointers for different types may differ.  Programmers don't need to know the internal values, but the compiler must be told which type of null pointer is required, so it can make the necessary distinction.  It can be told through context, though in some cases (e.g. in a function call with no prototype in scope, or as a variable argument in a varargs function) it should be explicitly cast.

Note that it is the compiler's responsibility to generate whatever bit pattern a machine uses for that null pointer.  That is, the programmer uses 0 or NULL, but the compiler will translate that into the correct value.

NULL is defined in <locale.h>, <stddef.h>, <stdio.h>, <stdlib.h>, <string.h>, and <time.h>.

A null pointer should not be thought of as pointing at address 0.

Examples of nonzero null pointer values are:

Bibliography: C Programming FAQs: Frequently Asked Questions by Steve Summit, Addison-Wesley, 1996.

Last modified: Thu 14 December 2000