Skip to main content
A null pointer is a special pointer value guaranteed not to point to any valid object or function in memory. It serves as a sentinel value at the language level, representing an uninitialized or intentionally empty memory address state. In C, a null pointer is created by assigning a null pointer constant to a pointer variable. The C standard defines a null pointer constant as any integer constant expression with the value 0, or such an expression cast to type void *. Valid source code representations include 0, 0L, 0x00, '\0', (1 - 1), or the standard macro NULL.

The C23 nullptr Keyword

To resolve type ambiguity and safety issues associated with the traditional NULL macro (which may evaluate to an integer type rather than a pointer), the C23 standard introduced the nullptr keyword and the nullptr_t type. nullptr is a dedicated null pointer constant of type nullptr_t that implicitly converts to any pointer type but does not implicitly convert to integer types (except bool).

Technical Characteristics

Memory Representation While a null pointer is represented in source code by an integer constant expression evaluating to zero (or nullptr), the underlying hardware bit-pattern is implementation-defined. The compiler translates the null pointer constant into the architecture’s specific null memory address. Although almost universally represented by all zero bits at the hardware level, the C standard does not strictly mandate this. Type Equivalence and Comparison A null pointer of one type is guaranteed to compare equal to a null pointer of any other type. When a null pointer constant is assigned to or compared with a pointer of a specific type, it is implicitly converted to a null pointer of that target type. A null pointer is also guaranteed to compare unequal to any pointer to a valid object or function.
Variadic Functions and NULL Passing the traditional NULL macro to a variadic function (such as printf or execl) without an explicit cast invokes Undefined Behavior. Because NULL can be defined simply as the integer 0, the compiler may push an integer onto the call stack instead of a pointer. If the variadic function expects a pointer, this type mismatch corrupts the stack or reads invalid data.
Dereferencing and Undefined Behavior Because a null pointer does not resolve to a valid memory location, attempting to dereference it (accessing or modifying the value it points to) invokes Undefined Behavior (UB).
On modern operating systems with virtual memory management, dereferencing a null pointer typically results in a hardware exception, such as a Segmentation Fault (SIGSEGV). This occurs because the zero page of virtual memory is intentionally left unmapped by the OS to trap these exact memory access violations. Pointer Arithmetic Performing pointer arithmetic on a null pointer is strictly undefined behavior in C.
The C standard dictates that pointer arithmetic is only valid when the pointer points to an element of an array object (or one past the last element). Since a null pointer points to no object, any arithmetic operation violates this constraint.
Tired of Poor C Skills? Fix That With Deep Grasping!Learn More