๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ null-pointer-in-c
NULL Pointer in C - GeeksforGeeks
By doing so, we can perform error ... donโ€™t want to pass any valid memory address. A NULL pointer is used in data structures like trees, linked lists, etc....
Published: January 10, 2025
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_null_pointer.htm
NULL Pointer in C
To check for a null pointer before ... variable only if it's not NULL. A NULL pointer is always used to detect the endpoint of trees, linked lists, and other dynamic ......
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
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
Why is there a NULL in the C language? - Stack Overflow
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. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Question: Why are NULL pointers so ridiculously hated?
Looking at it the other way around, what advantage does the use of null provide over an option/result type? More on reddit.com
๐ŸŒ r/ProgrammingLanguages
90
0
May 25, 2023
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ pointers โ€บ null pointer
C | Pointers | Null Pointer | Codecademy
February 3, 2025 - ... In C, NULL is often defined as ((void \*)0). While NULL and 0 can be used interchangeably in many contexts, using NULL improves code readability, making it clear that the value is a pointer rather than an integer.
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_null.php
C NULL
It helps you avoid using pointers that are empty or invalid. You can compare a pointer to NULL to check if it is safe to use.
๐ŸŒ
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 - A null pointer in C does not point to any memory location. They are used in dynamic memory allocation, error handling, initialization of other pointers and more.
๐ŸŒ
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 - Null pointers are used to avoid crashing down of the program: As we saw earlier if we declare any pointer without assigning anything to it then it takes garbage value where it may result in crashing of the system program.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
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 - Error Detection: Functions often return null pointers to indicate that something went wrong (e.g., failure in memory allocation). Control Structures: In data structures like linked lists and trees, null pointers are used to mark the end of a list or the absence of a child node.
Find elsewhere
๐ŸŒ
CSEstack
csestack.org โ€บ home โ€บ 3 major use of null pointer in c programming | what does actually null means?
3 Major use of NULL Pointer in C Programming | What does actually NULL means?
March 9, 2019 - Here is a simple C program to print the value of NULL macro. ... We can use this NULL constant value to assign to any pointer so that it will not 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 example below, We create a pointer *ptr and assign it the value NULL to indicate that it doesn't point to any variables. We add a condition after creating a pointer variable that checks if the value of the pointer is null. ... The built-in malloc() method is used to allocate memory in ...
๐ŸŒ
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.
๐ŸŒ
Lysator
lysator.liu.se โ€บ c โ€บ c-faq โ€บ c-1.html
Null Pointers
As a matter of style, many people prefer not to have unadorned 0's scattered throughout their programs. For this reason, the preprocessor macro NULL is #defined (by <stdio.h> or <stddef.h>), with value 0 (or (void *)0, about which more later). A programmer who wishes to make explicit the distinction between 0 the integer and 0 the null pointer can then use NULL whenever a null pointer is required.
๐ŸŒ
Dot Net Tutorials
dotnettutorials.net โ€บ home โ€บ null pointer in c
Null Pointer in C Language with Examples - Dot Net Tutorials
November 16, 2023 - Itโ€™s a special type of pointer used to indicate that it is not intended to point to an accessible memory location. Using a null pointer is essential for error handling and to avoid undefined behavior caused by uninitialized or dangling pointers.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ c-using-null-pointer-in-c-programming-123293
Using Null Pointer in C Programming
In C programming, a null pointer is represented by the constant NULL, which is defined in the header file stdio.h. Using a null pointer can help to avoid errors and add functionality to C programs. In this lab, you will learn about null pointers and how to use them in C programming.
๐ŸŒ
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!

๐ŸŒ
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.
๐ŸŒ
CodeWithHarry
codewithharry.com โ€บ tutorial โ€บ c-null-pointer
NULL Pointer | C Tutorial | CodeWithHarry
A NULL pointer is used for comparison with other pointers to check whether that other pointer itself is pointing to some memory address or not. We use it for error handling in the case of C programming.
๐ŸŒ
PiEmbSysTech
piembsystech.com โ€บ home โ€บ programming languages โ€บ null pointer in c language
Null Pointer in C Language - PiEmbSysTech - Embedded Systems & VLSI Lab
September 15, 2023 - Certainly, here are some examples ... for Null Pointers in C Language: Null pointers are commonly used to check if memory allocation was successful: int *ptr = NULL; ptr = (int *)malloc(sizeof(int)); if (ptr != NULL) { // ...
๐ŸŒ
Eskimo
eskimo.com โ€บ ~scs โ€บ cclass โ€บ notes โ€บ sx10d.html
10.4 Null Pointers
You can use a null pointer as a placeholder to remind yourself (or, more importantly, to help your program remember) that a pointer variable does not point anywhere at the moment and that you should not use the ``contents of'' operator on it (that is, you should not try to inspect what it points ...
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.