a value indicating that a pointer does not refer to a valid object
Wikipedia
en.wikipedia.org βΊ wiki βΊ Null_pointer
Null pointer - Wikipedia
2 weeks ago - There are occasions when dereferencing a pointer to address zero is intentional and well-defined; for example, BIOS code written in C for 16-bit real-mode x86 devices may write the interrupt descriptor table (IDT) at physical address 0 of the machine by dereferencing a pointer with the same value as a null pointer for writing.
GeeksforGeeks
geeksforgeeks.org βΊ c language βΊ null-pointer-in-c
NULL Pointer in C - GeeksforGeeks
By specifically mentioning the NULL pointer, the C standard gives a mechanism using which a C programmer can check whether a given pointer is legitimate or not. The malloc() function returns the NULL pointer when the memory allocation is failed.
Published Β January 10, 2025
Checking for null pointers when 0 is a valid address
C does not require the bit pattern of the null pointer to be 0, and there is at least one compiler that will let you change it. TenDRA's -f translator option makes it 0x55555555. Here's a Godbolt example. In practice, this will give you trouble because your code or a library you use likely ... More on reddit.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
Understanding difference between 0 and NULL
NULL is a macro that expands to a null pointer constant. 0 is a null pointer constant. That means NULL could just be defined as 0. Put simply, sizeof (NULL) is simply not something you can rely on as having a consistent, implementation-independent meaning β you don't even know what type NULL has. It is entirely possible for sizeof (NULL) to be not equal to sizeof (void *). If you want to know how big a particular pointer type is, use sizeof on that pointer type, or on a value of that pointer type. More on reddit.com
You're dereferencing a null pointer!
Dereferencing a null pointer does indeed deserve a whack to the back of the head. More on reddit.com
What is a null pointer in C?
A null pointer in C is a pointer that does not point to any valid memory location and is assigned the value NULL.
wscubetech.com
wscubetech.com βΊ resources βΊ c-programming βΊ null-pointer
Null Pointer in C Language (Uses, Best Practices, Examples)
What is the value of a null pointer in C?
The value is NULL, which is usually defined as ((void *)0) or 0, depending on the system.
wscubetech.com
wscubetech.com βΊ resources βΊ c-programming βΊ null-pointer
Null Pointer in C Language (Uses, Best Practices, Examples)
Can null pointers be assigned to multiple pointer types?
Yes, NULL can be assigned to any pointer regardless of type.
wscubetech.com
wscubetech.com βΊ resources βΊ c-programming βΊ null-pointer
Null Pointer in C Language (Uses, Best Practices, Examples)
Videos
04:06
What is a C++ null pointer? β - YouTube
18:59
NULL Pointer | C Programming Tutorial - YouTube
05:51
What is Null Pointer in C. #pointer #cprogramming #gcc - YouTube
04:13
C/C++: The NULL Pointer and Why It Matters - YouTube
03:56
Null Pointer in C with Example | C Programming Tutorials - YouTube
08:29
C++ Null Pointers - YouTube
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!
Top answer 1 of 5
4
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.
2 of 5
3
NULL is better thought of as a value of "nothing" rather than a value of zero. Using numbers is a good way to explain it, though. Say you want to accept an integer. Well most languages default new integers at 0. But then say you want 0 to mean something different than the person not supplying a number at all (e.g. undefined or null). Then you could accept a pointer to an integer instead. That pointer could be to an actual number (e.g. 0 or 1), but also to NULL to mean "nothing" (or undefined, or give me the default behavior, or whatever the program defines it as).
TutorialsPoint
tutorialspoint.com βΊ cprogramming βΊ c_null_pointer.htm
NULL Pointer in C
Checking if the FILE pointer returned by the fopen() function is NULL is always a recommended approach to avoid runtime errors in file-related processing. The following example shows how you can use the NULL file pointer to ensure that a file is accessible or not β
Scaler
scaler.com βΊ home βΊ topics βΊ what is null pointer in c?
What is Null Pointer in C? - Scaler Topics
September 4, 2023 - A null pointer refers to the 0th memory location, which is a shared memory area that can't be dereferenced. 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.
WsCube Tech
wscubetech.com βΊ resources βΊ c-programming βΊ null-pointer
Null Pointer in C Language (Uses, Best Practices, Examples)
March 18, 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.
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 - The incorrectUse() function directly dereferences the pointer without checking if it's NULL. This results in undefined behavior because we're attempting to access memory that doesn't exist. This example shows why it is important to check if the NULL pointer was successfully created in dynamic memory allocation.
ScienceDirect
sciencedirect.com βΊ topics βΊ computer-science βΊ null-pointer
Null Pointer - an overview | ScienceDirect Topics
Dereferencing a null pointer can lead to unexpected and severe behavior, including kernel crashes. A classic example involves a kernel module where dereferencing a null pointer caused a panic and a crash report indicating a null pointer bug in the init_module function.
Codecademy
codecademy.com βΊ docs βΊ pointers βΊ null pointer
C | Pointers | Null Pointer | Codecademy
February 3, 2025 - #include <stddef.h> pointer_type *pointer_name = NULL; ... In the example, we declare an integer pointer ptr and initialize it to NULL, indicating that it doesnβt point to any valid memory location:
Tutorialspoint
tutorialspoint.com βΊ cplusplus βΊ cpp_null_pointers.htm
C++ Null Pointers
#include <iostream> using namespace std; int main () { int *ptr = NULL; cout << "The value of ptr is " << ptr ; return 0; } When the above code is compiled and executed, it produces the following result β ... On most of the operating systems, programs are not permitted to access memory at address 0 because that memory is reserved by the operating system. However, the memory address 0 has special significance; it signals that the pointer is not intended to point to an accessible memory location.
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.
IncludeHelp
includehelp.com βΊ c-programs βΊ an-example-of-null-pointer-in-c.aspx
An Example of Null pointer in C
March 10, 2024 - ptr1 is initialized with the address of the integer variable num, thus ptr1 contains a valid memory address. ptr2 is uninitialized and ptr3 assigned 0. Thus, ptr2 and ptr3 are the NULL pointers.
Electro4u
electro4u.net βΊ blog βΊ what-is-a-null-pointer-55
Understanding Null Pointers: Definition, Examples, and Solutions
Error handling: In some cases, a function may return a null pointer to indicate that an error occurred during its execution. For example, if a function that allocates memory fails to allocate the requested amount of memory, it may return a null pointer to indicate the failure.
CodeWithHarry
codewithharry.com βΊ tutorial βΊ c-null-pointer
NULL Pointer | C Tutorial | CodeWithHarry
The dereferencing behavior of a NULL pointer is very much similar to that of a void pointer. A NULL pointer itself is a kind of a VOID pointer and hence, we have to typecast it into any data type the way we do to a void pointer before dereferencing.
Sanfoundry
sanfoundry.com βΊ c-tutorials-null-pointer
NULL Pointer in C Programming with Examples - Sanfoundry
December 31, 2025 - Dereferencing NULL Pointers: Attempting to access the value pointed to by a NULL pointer leads to segmentation faults. ... Assuming Non-NULL Without Checks: Never assume a pointer is valid without checking for NULL, especially when dealing with dynamic memory or external function returns.
Grokipedia
grokipedia.com βΊ null pointer
Null pointer β Grokipedia
January 14, 2026 - Consider an example in x86 assembly, where dereferencing a null pointer might compile to an instruction like mov eax, [0], which loads the value at memory address 0 into the EAX register.
Lenovo
lenovo.com βΊ home
Null Pointer in Programming β Definition, Uses, and Common Pitfalls | Lenovo US
Yes, null pointers are widely used in conditional statements to test whether a pointer is valid or not. For example, by checking if a pointer is null, developers ensure safe logic execution.
Learn C++
learncpp.com βΊ cpp-tutorial βΊ null-pointers
12.8 β Null pointers β Learn C++
August 12, 2015 - We can easily avoid dereferencing a null pointer by using a conditional to ensure a pointer is non-null before trying to dereference it: // Assume ptr is some pointer that may or may not be a null pointer if (ptr) // if ptr is not a null pointer std::cout << *ptr << '\n'; // okay to dereference else // do something else that doesn't involve dereferencing ptr (print an error message, do nothing at all, etc...)