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 indicating that the pointer or reference does not refer to an object. Programs routinely use … Wikipedia
🌐
Wikipedia
en.wikipedia.org › wiki › Null_pointer
Null pointer - Wikipedia
June 13, 2026 - 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 ...
Discussions

What happens when dereferencing a nullptr?
Dereferencing a null pointer is undefined behavior. In practice, trying to dereference null usually results in a seg-fault, but sometimes the compiler can optimize out the operation entirely. In your example, *p == true; doesn't actually change any of the program state, so the compiler is being smart and removing the extra computation. In the cout line, your program is actually using the result of the computation so it can't be removed. Note: In some cases an aggressive optimizer may recognize that dereferencing a null pointer would be undefined behavior and assume that the pointer therefore cannot be null. This can lead to some unintuitive and hard to find bugs. More on reddit.com
🌐 r/cpp_questions
20
14
August 18, 2022
c - What exactly is meant by "dereferencing a NULL pointer"? - Stack Overflow
Null termination of strings is just a value zero, often referred to either as nul (one L) or '\0' (an octal escape sequence), just to separate it from null pointers and NULL. ... Having cleared that out, we cannot access what a null pointer points at, because it is as mentioned a well-defined "nowhere". The process of accessing what a pointer points at is known as dereferencing... More on stackoverflow.com
🌐 stackoverflow.com
Address sanitizer give a hint that it's a NULL pointer dereference rather than zero page
Hello Currently a NULL pointer dereference gives this error "Hint: address points to the zero page" Seems a bit of an obscure hint. Could it be changed to just say "NULL pointer dere... More on github.com
🌐 github.com
4
February 24, 2023
c++ - when is dangeraous using dereference to 0 pointer? - Stack Overflow
For example, in some embedded systems, address zero is a vector that contains the address of the starting program. To read the value of the address vector, one has to assign a pointer with the value zero and dereference it. More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 5
48

C does not prohibit dereferencing the null pointer, it merely makes it undefined behavior.

If your environment is such that you're able to dereference a pointer containing the address 0x0, then you should be able to do so. The C language standard says nothing about what will happen when you do so. (In most environments, the result will be a program crash.)

A concrete example (if I'm remembering this correctly): On the 68k-based Sun 3 computers, dereferencing a null pointer did not cause a trap; instead, the OS stored a zero value at memory address zero, and dereferencing a null pointer (which pointed to address zero) would yield that zero value. That meant, for example, that a C program could treat a null pointer as if it were a valid pointer to an empty string. Some software, intentionally or not, depended on this behavior. This required a great deal of cleanup when porting software to the SPARC-based Sun 4, which trapped on null pointer dereferences. (I distinctly remember reading about this, but I was unable to find a reference; I'll update this if I can find it.)

Note that the null pointer is not necessarily address zero. More precisely, the representation of a null may or may not be all-bits-zero. It very commonly is, but it's not guaranteed. (If it's not, then the integer-to-pointer conversion of (void*)0 is non-trivial.)

Section 5 of the comp.lang.c FAQ discusses null pointers.

2 of 5
19

How do people actually use 0x0 when it's needed?

By either:

  • writing the required code in assembly language, or
  • writing the code in C and verifying that their compiler generates correct assembly language for the desired operation
🌐
Reddit
reddit.com › r/cpp_questions › what happens when dereferencing a nullptr?
r/cpp_questions on Reddit: What happens when dereferencing a nullptr?
August 18, 2022 -

I saw this code in A Tour of C++, but with a bit modify for illustration:

#include <iostream>

int main() {
  char s = 'a';
  char *p = &s;
  while (*p) {
    std::cout << *p;
    p++;
  }
  p = nullptr;
  //std::cout << (*p == true);
  *p == true;
}

I do not know how does while (*p) { end while I do not know what happens when p is nullptr. And std::cout << (*p == true) will induce segment fault but *p == true does not.

🌐
MathWorks
mathworks.com › polyspace bug finder › reviewing and reporting results › polyspace bug finder results › defects › static memory defects
Dereference of a null pointer - NULL pointer dereferenced - MATLAB
This defect occurs when you use a pointer with a value of NULL as if it points to a valid memory location. If you dereference the zero address, such as 0x00, Polyspace® considers the null address as equivalent to NULL and raises this defect.
🌐
Medium
medium.com › @chanibonner › a-beginners-guide-to-null-pointer-dereference-attacks-d3618cc8a493
A Beginner’s Guide to Null Pointer Dereference Attacks | by Chani Bonner | Medium
February 25, 2024 - Yes, to answer the question from earlier, dereferencing is a real word. It means to access and work with a pointer as though you were working with the variable. What does that mean exactly? Remember, pointers don’t contain the value of the variable they point to.
🌐
OWASP Foundation
owasp.org › www-community › vulnerabilities › Null_Dereference
Null Dereference | OWASP Foundation
A null-pointer dereference takes place when a pointer with a value of NULL is used as though it pointed to a valid memory area.
Find elsewhere
Top answer
1 of 8
118

A NULL pointer points to memory that doesn't exist. This may be address 0x00000000 or any other implementation-defined value (as long as it can never be a real address). Dereferencing it means trying to access whatever is pointed to by the pointer. The * operator is the dereferencing operator:

int a, b, c; // some integers
int *pi;     // a pointer to an integer

a = 5;
pi = &a; // pi points to a
b = *pi; // b is now 5
pi = NULL;
c = *pi; // this is a NULL pointer dereference

This is exactly the same thing as a NullReferenceException in C#, except that pointers in C can point to any data object, even elements inside an array.

2 of 8
56

Dereferencing just means accessing the memory value at a given address. So when you have a pointer to something, to dereference the pointer means to read or write the data that the pointer points to.

In C, the unary * operator is the dereferencing operator. If x is a pointer, then *x is what x points to. The unary & operator is the address-of operator. If x is anything, then &x is the address at which x is stored in memory. The * and & operators are inverses of each other: if x is any data, and y is any pointer, then these equations are always true:

*(&x) == x
&(*y) == y

A null pointer is a pointer that does not point to any valid data (but it is not the only such pointer). The C standard says that it is undefined behavior to dereference a null pointer. This means that absolutely anything could happen: the program could crash, it could continue working silently, or it could erase your hard drive (although that's rather unlikely).

In most implementations, you will get a "segmentation fault" or "access violation" if you try to do so, which will almost always result in your program being terminated by the operating system. Here's one way a null pointer could be dereferenced:

int *x = NULL;  // x is a null pointer
int y = *x;     // CRASH: dereference x, trying to read it
*x = 0;         // CRASH: dereference x, trying to write it

And yes, dereferencing a null pointer is pretty much exactly like a NullReferenceException in C# (or a NullPointerException in Java), except that the langauge standard is a little more helpful here. In C#, dereferencing a null reference has well-defined behavior: it always throws a NullReferenceException. There's no way that your program could continue working silently or erase your hard drive like in C (unless there's a bug in the language runtime, but again that's incredibly unlikely as well).

🌐
Snyk Learn
learn.snyk.io › home › security education › what is a null dereference? | tutorial & examples
What is a null dereference? | Tutorial & examples | Snyk Learn
August 15, 2024 - A null pointer dereference, on the other hand, is a specific type of null dereference that occurs when you try to access an object reference that has a null value in a programming language that uses pointers.
🌐
Quora
quora.com › What-actually-happens-when-dereferencing-a-NULL-pointer-Usually-the-process-terminates-Does-the-reaction-depend-on-the-operating-system-or-is-it-controlled-by-the-compiler-Is-it-mandatory-that-NULL-always-be-defined-as-“0”-with-proper-casting
What actually happens when dereferencing a NULL pointer? Usually, the process terminates. Does the reaction depend on the operating syste...
Answer (1 of 10): C/C++ are different from most of the popular languages: there is no runtime environment, there are no runtime checks, the actual machine language instructions will be generated and executed performing the read/write access at address zero. The behavior is entirely HW dependent. ...
🌐
LWN.net
lwn.net › Articles › 342780
A zero pointer is not a null pointer [LWN.net]
Posted Jul 22, 2009 9:02 UTC (Wed) ... to: A zero pointer is not a null pointer by tialaramex Parent article: Fun with NULL pointers, part 1 · It would be possible to keep 0x0 for the null pointer while respecting the C99 standard: the compiler would need to put in a couple of extra instructions for every pointer comparison making sure that 0x0 != P for any value of P. Optionally, it could also put in a check before every pointer dereference making sure ...
🌐
8th Light
8thlight.com › home › insights › dereferencing null pointer, without a seg fault
8th Light | Dereferencing NULL Pointer, without a Seg Fault
March 5, 2024 - Yes, it actually did what it was not supposed to do. I don't create any cows, I dereference and operate on address 0 (which is a big no no), and yet the program runs to completion, it milks some cow somewhere, and everybody's happy.
🌐
Mayhem Security
mayhem.security › blog › what-is-null-pointer-dereference
What Is Null Pointer Dereference? | Mayhem
June 1, 2022 - A null pointer dereference is a programming error that can occur when a program attempts to deference a null pointer.
🌐
Quora
quora.com › What-does-it-mean-when-you-dereference-a-pointer-and-its-null
What does it mean when you dereference a pointer and it's null? - Quora
Answer (1 of 3): It means that in C the program will crash with a segmentation fault; it is not allowed to access address [code ]0x0000000000[/code] in memory for user programs. In a language that uses pointers but have exception mechanisms such as C++, objective C, C#, D, Fortan, Rust, Go, Ada,...
🌐
GitHub
github.com › google › sanitizers › issues › 1626
Address sanitizer give a hint that it's a NULL pointer dereference rather than zero page · Issue #1626 · google/sanitizers
February 24, 2023 - Hello Currently a NULL pointer dereference gives this error "Hint: address points to the zero page" Seems a bit of an obscure hint. Could it be changed to just say "NULL pointer dere...
Author: google
🌐
Stack Overflow
stackoverflow.com › questions › 24810081 › when-is-dangeraous-using-dereference-to-0-pointer
c++ - when is dangeraous using dereference to 0 pointer? - Stack Overflow
The only time dereferencing a pointer to zero, is when there is memory at address zero, and address zero is accessible by the application (some OSes don't allow access to various address).
🌐
Google Groups
groups.google.com › g › ns-3-users › c › PZCVo4Royj4
msg="Attempted to dereference zero pointer"
May 8, 2023 - assert failed. cond="m_ptr", msg="Attempted to dereference zero pointer", +2.000000000s -1 file=./ns3/ptr.h, line=649 terminate called without an active exception.