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
2 weeks ago - However, C++11 introduced the explicit null pointer constant nullptr and type nullptr_t to be used instead, providing a type-safe null pointer. nullptr and type nullptr_t were later introduced to C in C23. Programming languages use different literals for the null pointer. In Java and C#, the literal null is provided as a literal for reference types. In Pascal and Swift, a null pointer is called nil. In Eiffel, it is called a void reference. In Rust, the absence of a value is denoted as None, but a true null pointer is std::ptr::null(). Because a null pointer does not point to a meaningful object, an attempt to dereference (i.e., access the data stored at that memory location) a null pointer usually (but not always) causes a run-time error or immediate program crash.
๐ŸŒ
Learn C++
learncpp.com โ€บ cpp-tutorial โ€บ null-pointers
12.8 โ€” Null pointers โ€“ Learn C++
August 12, 2015 - Value initialize your pointers (to be null pointers) if you are not initializing them with the address of a valid object. Because we can use assignment to change what a pointer is pointing at, a pointer that is initially set to null can later be changed to point at a valid object:
Discussions

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
c++ - How to assign a value to a pointer that points to NULL - Stack Overflow
I have a pointer that points to null, and i want to assign it a value. But if i deference it, I get an error. I have tried this: *nullPointer = value; but like I said, I get an error. How can I do... More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
function - C Assign Pointer to NULL - Stack Overflow
Copy#include #include ... *a = NULL; } ... Save this answer. ... Show activity on this post. in C, a function call like foo(a) will never change the value of a. ... Save this answer. ... Show activity on this post. Your function should take a char** a if you want to modify what it points to. This is because pointers are copied ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
People also ask

What is a null pointer?
A null pointer is a special type of pointer in programming that points to no valid memory location or object. It is used to indicate that the pointer doesnโ€™t contain a usable or meaningful memory address. Null pointers help programmers signify the absence of a value or the end of certain processes in data structures, ensuring clarity and preventing unexpected behaviors in the program.
๐ŸŒ
lenovo.com
lenovo.com โ€บ home
Null Pointer in Programming โ€“ Definition, Uses, and Common Pitfalls ...
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 ...
Does a null pointer always point to address zero in memory?
Although the value typically represents null pointers zero, they donโ€™t always point to memory address 0 in all systems. The C and C++ standards only guarantee that a null pointer compares equal to zero, but do not enforce its actual memory location, leaving implementations room for optimization based on different architectures.
๐ŸŒ
lenovo.com
lenovo.com โ€บ home
Null Pointer in Programming โ€“ Definition, Uses, and Common Pitfalls ...
๐ŸŒ
Lenovo
lenovo.com โ€บ home
Null Pointer in Programming โ€“ Definition, Uses, and Common Pitfalls | Lenovo US
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.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ cplusplus โ€บ cpp_null_pointers.htm
C++ Null Pointers
But by convention, if a pointer contains the null (zero) value, it is assumed to point to nothing.
๐ŸŒ
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!

๐ŸŒ
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 - Not only this program compiles but executes successfully to give the output as Output: ... Explanation: What happens here is that when a Null pointer is created, it points to null, without any doubt.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c++ โ€บ null-pointer-in-cpp
NULL Pointer in C++ - GeeksforGeeks
A NULL pointer in C++ represents a pointer that does not refer to any valid memory address. It indicates that the pointer is intentionally set to point to nothing and holds the value NULL (or nullptr in C++11 and later).
Published ย  January 12, 2026
๐ŸŒ
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.
Published ย  January 10, 2025
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ pointers โ€บ null pointer
C | Pointers | Null Pointer | Codecademy
February 3, 2025 - It is a common practice to initialize pointers to NULL to avoid them pointing to random or undefined memory locations.
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
IBM
ibm.com โ€บ docs โ€บ en โ€บ i โ€บ 7.3.0
Null pointers - IBM Documentation
October 7, 2025 - You can specify any of the following ... defined before use. ... You can use an integer constant expression with the value 0 or an expression that is cast to(void *)0 as a null pointer constant....
๐ŸŒ
Quora
quora.com โ€บ How-do-you-assign-a-value-to-a-pointer-that-points-to-null-C-development
How to assign a value to a pointer that points to null (C++, development) - Quora
For APIs that require out-parameters, ... ... Assign using &object, new, or another pointer. Use nullptr for null, avoid dereferencing until the pointer points to valid storage....
๐ŸŒ
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 first pointer intPtr is an integer type pointer, and floatPtr is a floating-point type pointer. We initialize them both to NULL, which indicates that neither pointer currently points to any valid memory location.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ what is null pointer in c?
What is Null Pointer in C? - Scaler Topics
September 4, 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.
Top answer
1 of 6
48

It's because the pointer is passed by value and not by reference. If you want to change the pointer inside the function you need to pass the actual pointer as a pointer, i.e. a pointer to a pointer:

Copyvoid my_function(char **a)
{
    *a = NULL;
}

Use the address-of operator & when you call the function to get the address of the pointer:

Copymy_function(&ptr);
2 of 6
8

Your statement a=NULL in my_function() indeed sets the value of a to NULL, but a is a local variable of that function.When you passed ptr to my_function() in main(), the value of ptr was copied to a.I suppose your whole confusion arose from the * used before a in the definition of my_function().

Pointers are generally passed to functions when we want to manipulate the original values which those pointers point to, from the called function, and this is done by dereferencing those pointers from the called functions.In this case, had you used this:

Copy*a= blah blah;

it would have reflected in the value at the address pointed to by ptr in main().But since you want to change the value of ptr itself, you need to be able to have a way to manipulate it from my_function().For this you use a pointer-to-pointer,ie of type char**.You pass such a char** as argument to my_function(() and use it to alter the value of ptr.Here's the variation to your code that would do it for you:

Copy#include <stdlib.h>
#include <stdio.h>

void my_function(char **); // Change char* to char**

int main(int argc, char *argv[]) {
    char *ptr;
    ptr = malloc(10);

    if(ptr != NULL) printf("FIRST TEST: ptr is not null\n");
    else printf("FIRST TEST: ptr is null\n");

    my_function(&ptr); //You pass a char**

    if(ptr != NULL) printf("SECOND TEST: ptr is not null\n");
    else printf("SECOND TEST: ptr is null\n");
}

void my_function(char **a) {  //Change char* to char** here
    *a = NULL;
}
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ cpp โ€บ extensions โ€บ nullptr-cpp-component-extensions
nullptr (C++/CLI and C++/CX) | Microsoft Learn
June 25, 2025 - Use a null pointer value to indicate that an object handle, interior pointer, or native pointer type does not point to an object.