๐ŸŒ
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:
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
3 weeks ago - Dereferencing a null pointer is undefined behavior in C, and a conforming implementation is allowed to assume that any pointer that is dereferenced is not null. In practice, dereferencing a null pointer may result in an attempted read or write from memory that is not mapped, triggering a segmentation fault or memory access violation. This may manifest itself as a program crash, or be transformed into a software exception that can be caught by program code.
๐ŸŒ
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 program or to prevent segmentation fault errors.
๐ŸŒ
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 - A null pointer in C does not point to any memory location. They are used in dynamic memory allocation, error handling, etc. Any pointer which is assigned the value NULL becomes a null pointer.
๐ŸŒ
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.
๐ŸŒ
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.
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Javatpoint
javatpoint.com โ€บ null-pointer-in-c
Null Pointer in C - javatpoint
Null Pointer in C with programming examples for beginners and professionals covering concepts, control statements, c array, c pointers, c structures, c union, c strings and more.
Find elsewhere
๐ŸŒ
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.
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.

๐ŸŒ
Dot Net Tutorials
dotnettutorials.net โ€บ home โ€บ null pointer in c
Null Pointer in C Language with Examples - Dot Net Tutorials
November 16, 2023 - A null pointer points to the 0th memory location, a reserved memory that cannot be dereferenced. In the below example, we create a pointer *ptr and assign a NULL value to the pointer, which means that it does not point to any variable.
๐ŸŒ
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
๐ŸŒ
CodeWithHarry
codewithharry.com โ€บ tutorial โ€บ c-null-pointer
NULL Pointer | C Tutorial | CodeWithHarry
A pointer that is not assigned any value or memory address but NULL is known as a NULL pointer. A NULL pointer does not point to any object, variable, or function. NULL pointers are often used to initialize a pointer variable, where we wish to represent that the pointer variable isnโ€™t currently ...
๐ŸŒ
Sanfoundry
sanfoundry.com โ€บ c-tutorials-null-pointer
NULL Pointer in C Programming with Examples - Sanfoundry
April 17, 2025 - Among various types of pointers, the NULL pointer holds a special place due to its significance in ensuring program stability and preventing errors. A NULL pointer is a pointer that does not point to any valid memory location.
๐ŸŒ
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!
Top answer
1 of 5
7

Actually, you can use a literal 0 anyplace you would use NULL.

Section 6.3.2.3p3 of the C standard states:

An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. 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.

And section 7.19p3 states:

The macros are:

NULL

which expands to an implementation-defined null pointer constant

So 0 qualifies as a null pointer constant, as does (void *)0 and NULL. The use of NULL is preferred however as it makes it more evident to the reader that a null pointer is being used and not the integer value 0.

2 of 5
5

NULL is used to make it clear it is a pointer type.

Ideally, the C implementation would define NULL as ((void *) 0) or something equivalent, and programmers would always use NULL when they want a null pointer constant.

If this is done, then, when a programmer has, for example, an int *x and accidentally writes *x = NULL;, then the compiler can recognize that a mistake has been made, because the left side of = has type int, and the right side has type void *, and this is not a proper combination for assignment.

In contrast, if the programmer accidentally writes *x = 0; instead of x = 0;, then the compiler cannot recognize this mistake, because the left side has type int, and the right side has type int, and that is a valid combination.

Thus, when NULL is defined well and is used, mistakes are detected earlier.

In particular answer to your question โ€œIs there a context in which just plain literal 0 would not work exactly the same?โ€:

  • In correct code, NULL and 0 may be used interchangeably as null pointer constants.
  • 0 will function as an integer (non-pointer) constant, but NULL might not, depending on how the C implementation defines it.
  • For the purpose of detecting errors, NULL and 0 do not work exactly the same; using NULL with a good definition serves to help detect some mistakes that using 0 does not.

The C standard allows 0 to be used for null pointer constants for historic reasons. However, this is not beneficial except for allowing previously written code to compile in compilers using current C standards. New code should avoid using 0 as a null pointer constant.