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
3 weeks ago - 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. Programs routinely use null pointers to represent conditions such as the end of a list of unknown length or the failure to perform some action; this use of null pointers can be compared to nullable types and to the Nothing value in an option type.
🌐
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
People also ask

What is the purpose of a null pointer in programming?
The main purpose of a null pointer is to serve as a placeholder when a pointer does not yet point to a valid memory location or object. It signals the absence of a value, ensuring that the program doesn’t attempt to access inaccessible or undefined memory. Additionally, null pointers are used to mark the termination of data structures like linked lists, simplifying logic and reducing errors.
🌐
lenovo.com
lenovo.com › home
Null Pointer in Programming – Definition, Uses, and Common Pitfalls ...
Can a null pointer be assigned to any data type?
Yes, a null pointer can be assigned to any pointer variable, regardless of its data type. This flexibility is because the null pointer doesn’t point to any actual data, but rather a special memory value, often zero. However, the interpretation of null pointers can vary slightly depending on the programming language, so caution should be exercised when implementing cross-language solutions.
🌐
lenovo.com
lenovo.com › home
Null Pointer in Programming – Definition, Uses, and Common Pitfalls ...
What is the difference between a null pointer and an uninitialized pointer?
A null pointer explicitly points to “nothing” and holds a defined null value, like zero, while an uninitialized pointer contains garbage or unpredictable data. Unlike null pointers, uninitialized pointers pose a significant risk of leading the program to access invalid memory, potentially causing serious errors.
🌐
lenovo.com
lenovo.com › home
Null Pointer in Programming – Definition, Uses, and Common Pitfalls ...
🌐
Reddit
reddit.com › r/learnprogramming › trying to understand null pointers
r/learnprogramming on Reddit: Trying to understand NULL pointers
December 30, 2021 -

Hello all again,

I have another stupid question here lol, so I'm trying to wrap my head around NULL. Im currently under the impression that NULL is a built in constant that has a value of zero, but what does that actually mean? When would it be appropriate to use null? If someone could explain it in layman's terms that would be super helpful!

🌐
Learn C++
learncpp.com › cpp-tutorial › null-pointers
12.8 — Null pointers – Learn C++
Dereferencing a pointer means “go to the address the pointer is pointing at and access the value there”. A null pointer holds a null value, which semantically means the pointer is not pointing at anything. So what value would it access? Accidentally dereferencing null and dangling pointers is one of the most common mistakes C++ programmers make, and is probably the most common reason that C++ programs crash in practice.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › null-pointer-in-cpp
NULL Pointer in C++ - GeeksforGeeks
It is also returned by several inbuilt functions as a failure response. Trying to dereference a NULL pointer i.e. trying to access the memory it points to leads to some undefined behavior leading to the program crash. We can create a NULL pointer of any type by simply assigning the value NULL ...
Published   July 23, 2025
🌐
IBM
ibm.com › docs › en › zos › 2.4.0
Null pointer constants
We cannot provide a description for this page right now
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_null_pointer.htm
NULL Pointer in C
A NULL pointer in C is a pointer that doesn't point to any of the memory locations. The NULL constant is defined in the header files stdio.h, stddef.h as well as stdlib.h.
Find elsewhere
🌐
Lenovo
lenovo.com › home
Null Pointer in Programming – Definition, Uses, and Common Pitfalls | Lenovo US
Don’t miss out on the latest ... ... Please review your cart as items have changed. ... A null pointer is a special type of pointer in programming that points to no valid memory location or object....
Top answer
1 of 4
8

The 0xCACACACA generated by Visual Studio is usually there for un-initialized pointers, for precisely this reason. When you see this, you know something is wrong. If it initialized it to 0, it can very well be expected behavior. This is only done in debug node, with full optimization the value of an uninitialized pointer would be just garbage.

And yes, NULL pointers don't have a value of 0 per say. 0 is just a literal. The actual value can be different. But the compiler is smart enough to abstract that away, so even if you have a NULL pointer whose value isn't really 0 (as in the number 0), comparing it to 0 or NULL would still yield true. It's better to think in terms of nullptr really.

2 of 4
4

This question previously appeared on the comp.lang.c newsgroup. You can read the archive with Google Groups

In that thread, Paul Sand quoted another source, "Portable C" by H. Rabinowitz and Chaim Schaap, as follows:

Certain Prime computers use a value different from all-bits-0 to encode the null pointer. Also, some large Honeywell-Bull machines use the bit pattern 06000 to encode the null pointer. On such machines, the assignment of 0 to a pointer yields the special bit pattern that designates the null pointer.

Similarly, (char *)0 yields the special bit pattern that designates a null pointer.

Where you'd commonly see non-null pointers is when working with physical memory addresses (that is, when there is no MMU or in kernel mode bypassing the MMU) and the machine has memory-mapped I/O at or near address 0. You want a null pointer to be way out in no-man's land, so that if you offset it (e.g. structure member access via a pointer) you won't get any useful address.

For your specific question, only an integral constant expression with value 0 is interpreted as a null pointer. So

char* p = (char*)i;

does not portably make p a null pointer (i.e. the Standard makes no such guarantee, but your particular compiler may).

🌐
Cppreference
en.cppreference.com › w › cpp › types › nullptr_t.html
std::nullptr_t - cppreference.com
std::nullptr_t is the type of the null pointer literal nullptr. It is a distinct type that is not itself a pointer type or a pointer to member type.
🌐
Unstop
unstop.com › home › blog › null pointer in c | a detailed explanation with examples
Null Pointer In C | A Detailed Explanation With Examples // Unstop
May 3, 2024 - They allow us to access and manipulate ... are four main types of pointers in the C programming language: null pointer, void pointer, wild pointer, and dangling pointer....
🌐
ScienceDirect
sciencedirect.com › topics › computer-science › null-pointer
Null Pointer - an overview | ScienceDirect Topics
In short, black is a meaningful default, null is a meaningless but not invalid default for pointers, and Image 21 is typically an invalid default for numbers—or at least this summarizes typical usage patterns. Unpacking the conceptual variations between different type-instances—meaningful, ...
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.

🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Null-Pointers.html
Null Pointers (GNU C Language Manual)
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. You can also do it by casting 0 to the desired pointer type, as in (char *) 0.
🌐
IBM
ibm.com › docs › en › xl-c-aix › 13.1.2
Null pointers
We cannot provide a description for this page right now
🌐
Scaler
scaler.com › topics › null-pointer-in-c
What is Null Pointer in C? - Scaler Topics
November 9, 2022 - 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. That is, the null pointer in C holds the value Null, but the type of the pointer is void.
🌐
Tutorialspoint
tutorialspoint.com › cplusplus › cpp_null_pointers.htm
C++ Null Pointers
It is always a good practice to assign the pointer NULL to a pointer variable in case you do not have exact address to be assigned. This is done at the time of variable declaration. A pointer that is assigned NULL is called a null pointer.
🌐
Eskimo
eskimo.com › ~scs › cclass › notes › sx10d.html
10.4 Null Pointers
The most straightforward way to ``get'' a null pointer in your program is by using the predefined constant NULL, which is defined for you by several standard header files, including <stdio.h>, <stdlib.h>, and <string.h>. To initialize a pointer to a null pointer, you might use code like
🌐
cppreference.com
en.cppreference.com › w › c › types › NULL.html
NULL - cppreference.com
POSIX requires NULL to be defined as an integer constant expression with the value ​0​ cast to void*. ... #include <inttypes.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> int main(void) { // any kind of pointer can be set to NULL int* p = NULL; struct S *s = NULL; void(*f)(int, ...
🌐
CodeWithHarry
codewithharry.com › tutorial › c-null-pointer
NULL Pointer | C Tutorial | CodeWithHarry
NULL pointers and void pointers very much sound similar just because of their nomenclatures, but they are very different as a NULL pointer is a pointer with a NULL value address, and a void pointer is a pointer of void data type.