๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ null-pointer-in-c
NULL Pointer in C - GeeksforGeeks
The Null Pointer is the pointer that does not point to any location but NULL. According to C11 standard: โ€œAn integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.
Published ย  January 10, 2025
a value indicating that a pointer does not refer to a valid object
In computing, a null pointer (sometimes shortened to nullptr or null) or null reference is a value saved for indicating that the pointer or reference does not refer to a valid object. โ€ฆ Wikipedia
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Null_pointer
Null pointer - Wikipedia
January 30, 2026 - It is one of the most common types of software weaknesses, and Tony Hoare, who introduced the concept, has referred to it as a "billion dollar mistake". In C, two null pointers of any type are guaranteed to compare equal.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ cprogramming โ€บ c null pointer
C Null Pointer
June 10, 2012 - A NULL pointer in C is a pointer that doesn't point to any of the memory locations.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ what is null pointer in c?
What is Null Pointer in C? - Scaler Topics
September 4, 2023 - In the C programming language, a null pointer is a pointer that does not point to any memory location and hence does not hold the address of any variables. It just stores the segment's base address.
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ null pointer in c | a detailed explanation with examples
Null Pointer In C | A Detailed Explanation With Examples
May 3, 2024 - We'll delve into what null pointers ... stores the memory address of another variable. A NULL pointer is a pointer that doesn't point to any usable memory address....
๐ŸŒ
GNU
gnu.org โ€บ software โ€บ c-intro-and-ref โ€บ manual โ€บ html_node โ€บ Null-Pointers.html
Null Pointers (GNU C Language Manual)
Next: Dereferencing Null or Invalid Pointers, Previous: Dereferencing Pointers, Up: Pointers [Contents][Index] A pointer value can be null, which means it does not point to any object. The cleanest way to get a null pointer is by writing NULL, a standard macro defined in stddef.h.
Top answer
1 of 3
4

In C, NULL is a macro that expands to a null pointer constant.

7.19p3

The macros are

NULL which expands to an implementation-defined null pointer constant; ...

A null pointer constant is an integer constant expression with the value 0 ( e.g., 0, 1-1, 42*0LL, etc.) or such an expression cast to (void*).

6.3.2.3p3

An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.66) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.

Most common C implementations define NULL to be 0, 0L, or ((void*)0).

So you are correct. NULL need not be a pointer.

(IIRC, C++ doesn't even allow the (void*) cast in NULL, meaning NULL in C++ always has integer type. Because of that and because void* pointers do not compare with regular pointers so readily in C++, C++>=11 now has a special nullptr keyword.)

2 of 3
3

NULL itself is not a pointer, it is a macro that can be used to initialize a pointer to the null pointer value of its type. When compared to a pointer, it compares equal if the pointer is a null pointer and unequal if the pointer is a valid pointer to an object of its type.

There is no semantic difference between char *p = 0; and char *p = NULL; but the latter is more explicit and using NULL instead of 0 is more informative in circumstances where the other operand is not obviously a pointer or if comparing to an integer looks like a type mismatch:

CopyFILE *fp = fopen("myfile", "r");
if (fp == NULL) {
    /* report the error */
}

Similarly, there is no semantical difference in C between '\0' and 0, they both are int constants. The first is the null byte, the second the null value. Using 0, '\0' and NULL wisely may seem futile but makes code more readable by other programmers and oneself too.

The confusion may come from misspelling or mishearing the null pointer as the NULL pointer. The C Standard was carefully proof read to only use null pointer and refer to NULL only as the macro NULL.

Note however that one the accepted definitions of NULL, #define NULL ((void*)0) makes NULL a null pointer to void.

Find elsewhere
๐ŸŒ
IBM
ibm.com โ€บ docs โ€บ en โ€บ xl-c-aix โ€บ 13.1.2
XL C for AIX
We cannot provide a description for this page right now
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ cprogramming โ€บ c null pointer
NULL pointer in C
June 10, 2012 - A NULL pointer in C is a pointer that doesn't point to any of the memory locations.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ c-programming โ€บ null-pointer
Null Pointer in C Language (Uses, Best Practices, Examples)
August 29, 2025 - Learn about the null pointer in C language, including its syntax, uses, how to check it, best practices, examples, and more. Read now!
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ pointers โ€บ null pointer
C | Pointers | Null Pointer | Codecademy
February 3, 2025 - A NULL pointer in C is a pointer that does not point to any valid memory location.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ c-using-null-pointer-in-c-programming-123293
Using Null Pointer in C Programming
A null pointer is a pointer that does not point to any memory address. In C programming, a null pointer is represented by the constant NULL, which is defined in the header file stdio.h.
๐ŸŒ
ScienceDirect
sciencedirect.com โ€บ topics โ€บ computer-science โ€บ null-pointer
Null Pointer - an overview | ScienceDirect Topics
In computer science, a null pointer is a pointer that does not point to any valid memory address. In C++, for example, a null pointer is conceptually not considered a โ€œrealโ€ pointer, as its meaning is that it does not reference any memory location. 1 Despite this, it is common practice ...
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_null.php
C NULL
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... NULL is a special value that represents a "null pointer" - a pointer that does not point to anything.
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ c programming tutorial โ€บ null pointer in c
Null pointer in C | How Null pointer work in C with Examples
March 28, 2023 - So the null pointer is defined as the pointer that is assigned to zero to make it null pointer or a pointer that does not store any valid memory address or an uninitialized pointer are known as a NULL pointer.
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Aticleworld
aticleworld.com โ€บ home โ€บ what is a null pointer in c/c++?
What is a Null Pointer in C/C++? - Aticleworld
January 25, 2023 - What is Null Pointer in C? Integer constant expression with value 0, or such an expression cast to type void *, is called a null pointer constant.
Top answer
1 of 7
26

The definition of NULL is a syntactic crutch to allow a programmer a clear expression that a pointer is, at certain times, pointing nowhere. It's meant for readability - and with increased compiler bloat even for automated checks.

On a hardware level there is no such thing. A pointer is a word, and a word always holds a valid number. So by convention zero was chosen - it could have been any other. Like -1 for example. Selecting 0 offered the advantage that a simple if(pointer) could be used to check if it's a valid pointer (or more correct, not 0).

So my question is what led some C standard to treat the NULL pointer differently from any other pointer?

C also doesn't treat NULL different from any other pointer. The C library in contrast does, but not because of NULL, but rather as its (runtime) value of 0 will make some functions fail, when used as input.

Did K&R want to target an exotic architecture or something?

No. It's a concept needed from a pure software engineering point of view. Having a syntactic construct to handle uninitialized pointers improves readability and possibly enables further checks.


Now, for the historic part, NULL is, like the related handling of TRUE/FALSE inherited from BCPL (through B). Just here it was called nil.


Even with that little historic bit, I'm not sure if Retrocomputing is the right place to ask for this, as it's about a basic concept in software engineering and not anything burdened with historic implication. So a quick search in Software Engineering and Stack Overflow shows that this question has been asked many times. It's something people always stumble on, isn't it?

2 of 7
24

The important thing you may be missing is that a null pointer in C is not required by the standard to have the same binary representation as the number zero. It is still a "normal" pointer, but it points to a special location that the program is not allowed to use.

The integer constant 0 is turned into nullptr when used as a pointer. Similarly, 0 will become 0.0 when used in floating-point calculations, or false in boolean operations. Coercions are not just one-way: if(ptr) will convert a pointer into a boolean which indicates whether the pointer is not null. All of these conversions serve to avoid requiring that a null pointer shares the same representation as zero.

Most machines represent integer zero as all-bits-zero and comparisons against that are particularly cheap, so it is worthwhile to arrange things so that sentinel values such as null pointers and end-of-string markers are all-bits-zero, and also that +0.0 and false are also all-bits-zero.

There is some subtlety in C in that a literal 0 is converted into nullptr, whereas casting an integer that happens to be zero into a pointer will produce a pointer to location zero. Because they are the same thing on modern platforms, a whole class of potential bugs go away.