๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ null-pointer-in-c
NULL Pointer in C - GeeksforGeeks
Though that doesn't mean it would show the same behavior across all the machines. As the value of NULL in predefined libraries is 0 and the pointer (that's pointing to NULL) is not pointing to any memory location, this behavior occurs. We can pass a NULL value for pointers that should not contain any value to the function in C.
Published: January 10, 2025
๐ŸŒ
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. A pointer is initialized to NULL to avoid the unpredicted behavior of a
Discussions

Trying to understand NULL pointers
NULL is equivalent to 0 and equivalent to nullptr (in C++). It's an address that is "universally invalid." You can store 0x2093704802934 in a pointer and it will be invalid too (I'm sure) but it's not a convention. NULL is this convention that says "the pointer is not valid" and/or "the pointer hasn't been initialized yet" or "the memory pointed to has been released and I have invalidated the pointer by setting it to NULL." You store this value in a "pointer", like "int* s = 0" to show that it is not pointing to anything. And in your code you will check whether the pointer (s in my example) is equal to NULL (invalid) or not (valid). First you create a pointer, then you initialize it, then you use it, then you release it. More on reddit.com
๐ŸŒ r/learnprogramming
18
1
December 30, 2021
c - The history of the NULL pointer - Retrocomputing Stack Exchange
As we know, in C to dereference a null pointer is undefined behaviour. From what I understand, the PDP-7 and the PDP-11 both have ordinary memory that can be written to and read from at address 0. ... More on retrocomputing.stackexchange.com
๐ŸŒ retrocomputing.stackexchange.com
February 6, 2018
Checking for NULL pointer in C/C++ - Stack Overflow
In a recent code review, a contributor is trying to enforce that all NULL checks on pointers be performed in the following manner: int * some_ptr; // ... if (some_ptr == NULL) { // Handle null- More on stackoverflow.com
๐ŸŒ stackoverflow.com
what is a null pointer in c - Stack Overflow
I tried looking online but I didn't know exactly what to type. The Google search results I got for 'NULL pointer' were different from what I expected. ... There is also a typo in n2.next = &n2;, meaning that we will never reach n3. I would just throw this bad example away and study some other code. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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.
๐ŸŒ
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!

๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_null.php
C NULL
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Practice Problems C Compiler C Syllabus C Study Plan C Interview Q&A ... NULL is a special value that represents a "null pointer" - a pointer that does not point to anything.
๐ŸŒ
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. That is, the null pointer in C holds the value Null, but the type of the pointer is void.
๐ŸŒ
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.
๐ŸŒ
Lysator
lysator.liu.se โ€บ c โ€บ c-faq โ€บ c-1.html
Null Pointers
To generate a null pointer in a function call context, an explicit cast is typically required, to force the 0 to be in a pointer context: ... If the (char *) cast were omitted, the compiler would not know to pass a null pointer, and would pass an integer 0 instead.
Find elsewhere
๐ŸŒ
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 - In C programming language pointers are used to point to the memory that is allocated dynamically or at run time and a pointer can be of any data type like int, float, char, etc. In this article, we are discussing the null pointer in C, where NULL is constant with value 0 in C.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Null_pointer
Null pointer - Wikipedia
June 13, 2026 - 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.
๐ŸŒ
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 - Any pointer which is assigned the value NULL becomes a null pointer. ... Pointers are powerful programming tools that store the memory address of variables, etc., elements of a program.
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.

๐ŸŒ
Uncodemy
uncodemy.com โ€บ blog โ€บ null-pointer-in-c-and-c-plus-plus-meaning-and-usage
Null Pointer in C and C++: Meaning and Usage
1 month ago - So, instead of holding an actual value like an integer or a character, it holds the location in memory where the value is stored. Now, a null pointer is a special type of pointer that doesnโ€™t point to any memory location.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ c-programming โ€บ null-pointer
Null Pointer in C Language (Uses, Best Practices, Examples)
July 27, 2026 - Learn in this tutorial about the null pointer in C, including its syntax, uses, how to check it, best practices, and examples to write efficient programs.
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:

FILE *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.

๐ŸŒ
StudyMite
studymite.com โ€บ blog โ€บ null-pointers-in-c
Null Pointer in C C Programming | StudyMite
August 2, 2026 - A null pointer points to nothing. It is assigned the value NULL, therefore it is called the null pointer. If you do not want the pointer to store any address then assign it to NULL.
๐ŸŒ
Dot Net Tutorials
dotnettutorials.net โ€บ home โ€บ null pointer in c
Null Pointer in C Language with Examples - Dot Net Tutorials
November 16, 2023 - In C programming, a null pointer is a pointer that does not point to any valid memory location. Itโ€™s a special type of pointer used to indicate that it is not intended to point to an accessible memory location.
๐ŸŒ
CodeWithHarry
codewithharry.com โ€บ tutorial โ€บ c-null-pointer
NULL Pointer | C Tutorial | CodeWithHarry
NULL pointers and uninitialized pointers are different, as a NULL pointer does not occupy any memory location. That means, it points to nowhere but to a zeroth location. In contrast, an uninitialized pointer means that the pointer occupies a garbage value address.