๐ŸŒ
Lenovo
lenovo.com โ€บ home
Null Pointer in Programming โ€“ Definition, Uses, and Common Pitfalls | Lenovo US
It acts as a sentinel value that tells the program or operating system that this pointer is inactive or uninitialized. By standardizing null values, memory is efficiently managed, and errors from using invalid memory locations are minimized. Yes, a null pointer can be assigned to any pointer variable, regardless of its data 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
Discussions

Why do we use Null pointers?
The value where a null pointer is pointing is irrelevant. A null pointer is a pointer that is pointing nowhere--there is no value. In C, the number 0 was defined as the representation of the null pointer. They could have picked any number, but it would have been painful. More on reddit.com
๐ŸŒ r/C_Programming
56
0
August 30, 2024
c - Is NULL a pointer? - Stack Overflow
Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... So, I had an argument with my professor earlier defending that NULL is not a pointer, but he kept on insisting that it is because there is such a thing as NULL ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
c - What is the difference between a pointer pointing to 0x0 location and a pointer set to NULL? - Software Engineering Stack Exchange
Is a pointer pointing to 0x0000 the same as a pointer set to NULL? If NULL value is defined in the C language, then what location does it physically translate to? Is it the same as 0x0000. Where ca... More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
January 4, 2012
arithmetic on NULL pointer -is it undefined behaviour?

The arithmetic itself is not undefined here. Look up how NULL is defined.

Edit: I stand corrected (see below)

More on reddit.com
๐ŸŒ r/C_Programming
64
19
August 7, 2019
People also ask

Can a null pointer be compared with other pointers?
Yes, null pointers can be compared to other pointers. This is a common practice to ensure that a pointer has been assigned a valid memory address. For example, checking whether a pointer is null before accessing it helps programmers avoid dereferencing errors. Such comparisons are straightforward and widely used in safe memory management.
๐ŸŒ
lenovo.com
lenovo.com โ€บ home
Null Pointer in Programming โ€“ Definition, Uses, and Common Pitfalls ...
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 ...
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 ...
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_null.php
C NULL
C Examples C Real-Life Examples C Exercises C Quiz 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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ what-is-a-pointer-to-a-null-pointer
What is a Pointer to a Null pointer - GeeksforGeeks
July 12, 2025 - Explanation: What happens here is that when a Null pointer is created, it points to null, without any doubt. But the variable of Null pointer takes some memory. Hence when a pointer to a null pointer is created, it points to an actual memory space, which in turn points to null.
Find elsewhere
๐ŸŒ
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 ...
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ cpp โ€บ extensions โ€บ nullptr-cpp-component-extensions
nullptr (C++/CLI and C++/CX) | Microsoft Learn
June 25, 2025 - The nullptr keyword is equivalent to Nothing in Visual Basic and null in C#. The nullptr keyword can be used anywhere a handle, native pointer, or function argument can be used.
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.

Top answer
1 of 7
20

A point that most of the answers here are not addressing, at least not explicitly, is that a null pointer is a value that exists during execution, and a null pointer constant is a syntactic construct that exists in C source code.

A null pointer constant, as Karlson's answer correctly states, is either an integer constant expression with the value 0 (a simple 0 is the most common example), or such an expression cast to void* (such as (void*)0).

NULL is a macro, defined in <stddef.h> and several other standard headers, that expands to an implementation-defined null pointer constant. The expansion is typically either 0 or ((void*)0) (the outer parentheses are needed to satisfy other language rules).

So a literal 0, when used in a context that requires an expression of pointer type, always evaluates to a null pointer, i.e., a unique pointer value that points to no object. That does not imply anything about the representation of a null pointer. Null pointers are very commonly represented as all-bits-zero, but they can be represented as anything. But even if a null pointer is represented as 0xDEADBEEF, 0 or (void*)0 is still a null pointer constant.

This answer to the question on stackoverflow covers this well.

This implies, among other things, that memset() or calloc(), which can set a region of memory to all-bits-zero, will not necessarily set any pointers in that region to null pointers. They're likely to do so on most implementations, perhaps even all existing ones, but the language doesn't guarantee it.

This question is really a duplicate of this one, but Stack Exchange doesn't allow marking duplicates across sites.

2 of 7
7

On most CPU architectures, which most likely includes whatever CPU architecture you are working on, a pointer pointing to 0x0000 is the exact same thing as a pointer set to NULL.

HOWEVER:

  • The C standard allows every platform out there to define the internal representation of NULL as it pleases.

  • The C standard says that if you assign zero to a pointer it will be converted to a NULL value for that platform, but if you take a NULL pointer and cast it to int, there are no guarantees that you will get zero back on every platform out there.

So, some hypothetical AcmePC CPU architecture might find it particularly convenient to represent NULL internally as 0x0badf00d, so assigning zero to a pointer will make it point to address 0x0badf00d, and casting that pointer back to int may yield 0x0badf00d.

I do not know of any architecture that works in such a bizarre way, but then again, the standard allows it, and I do not know every single CPU architecture in existence. So:

  • If you do not care at all about portability, then take NULL == 0 for granted.

  • If you care a little bit about portability, but are willing to leave out some systems which you have never heard of, then, again, go ahead and take NULL == 0 for granted.

  • But if you really care for portability, then go by what the standard says and only by what the standard says, and consider NULL as something completely unrelated to 0.

For more information you can look at The C Language Specification.

๐ŸŒ
C-faq
c-faq.com โ€บ null
Null Pointers
5.19 How can I access an interrupt vector located at the machine's location 0? If I set a pointer to 0, the compiler might translate it to some nonzero internal null pointer value.
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Null_pointer
Null pointer - Wikipedia
3 weeks ago - Prior to C23, the preprocessor macro NULL was provided, defined as an implementation-defined null pointer constant in <stdlib.h>, which in C99 can be portably expressed with #define NULL ((void*)0), the integer value 0 converted to the type void* (see pointer to void type). Since C23, a null pointer is represented with nullptr which is of type nullptr_t (first introduced to C++11), providing a type safe null pointer.
๐ŸŒ
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!
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ c-pointers
Pointers in C - GeeksforGeeks
Note: The actual size of the pointer ... or referred to in different contexts: The NULL Pointers are those pointers that do not point to any memory location....
Published ย  3 weeks ago
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ null-pointer-in-c
What is Null Pointer in C? - Scaler Topics
September 3, 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.
๐ŸŒ
Eskimo
eskimo.com โ€บ ~scs โ€บ cclass โ€บ notes โ€บ sx10d.html
10.4 Null Pointers
What this means is that no other valid pointer, to any other variable or array cell or anything else, will ever compare equal to a null pointer. 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
๐ŸŒ
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 - 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....