A null pointer has a reserved value that is called a null
pointer constant for indicating that the pointer does not point to
any valid object or function. You can use null pointers in the following
cases:
- Initialize pointers.
- Represent conditions such as the end of a list of unknown length.
- Indicate errors in returning a pointer from a function.
A null pointer constant is an integer constant expression
that evaluates to zero. For example, a null pointer constant can be
0, 0L, or such an expression that can be cast to
type (void *)0.
You can specify any of the following
values for a null pointer constant:
Note: NULL is a macro. It must be defined before
use.
Null pointer constants
- 0
- You can use an integer constant expression with the value 0 or
an expression that is cast to(void *)0 as a null
pointer constant.
- NULL
- The macro NULL and value 0 are equivalent as null pointer constants,
but NULL is cleaner because it represents the purpose of using the
constant for a pointer.