In C++11 and beyond, a pointer that is ==NULL will also ==nullptr and vice versa.

Uses of NULL other than comparing with a pointer (like using it to represent the nul byte at the end of a string) won't work with nullptr.

In some cases, NULL is #define NULL 0, as the integer constant 0 is special-cased in C and C++ when you compare it with pointers. This non-type type information causes some problems in both C and C++, so in C++ they decided to create a special type and value that does the same thing in the "proper" use cases, and reliably fails to compile in most of the "improper" use cases.

Insofar as your C++ implementation is compatible with the C implementation you are interoping with (very rare for this not to be true), everything should work.


To be very clear, if ptr is any kind of pointer, then the following expressions are equivalent in C++:

ptr == nullptr
ptr == NULL
ptr == 0
!ptr

As are the following:

ptr = nullptr
ptr = NULL
ptr = 0

and if X is some type, so are the following statements:

X* ptr = nullptr;
X* ptr = NULL;
X* ptr = 0;

nullptr differs when you pass it to a template function that deduces type (NULL or 0 become an int unless passed to an argument expecting a pointer, while nullptr remains a nullptr_t), and when used in some contexts where nullptr won't compile (like char c = NULL;) (note, not char* c=NULL;)

Finally, literally:

NULL == nullptr

is true.

The NULL constant gets promoted to a pointer type, and as a pointer it is a null pointer, which then compares equal to nullptr.


Despite all this, it isn't always true that:

 foo(NULL)

and

 foo(nullptr)

do the same thing.

void bar(int) { std::cout << "int\n"; }
void bar(void*) { std::cout << "void*\n"; }
template<class T>
void foo(T t) { bar(t); }
foo(NULL);
foo(nullptr);

this prints int for NULL and void* for nullptr.

Answer from Yakk - Adam Nevraumont on Stack Overflow
🌐
cppreference.com
en.cppreference.com › c › language › nullptr
Predefined null pointer constant (since C23) - cppreference.com
The keyword nullptr denotes a predefined null pointer constant. It is a non-lvalue of type nullptr_t.
Top answer
1 of 1
109

In C++11 and beyond, a pointer that is ==NULL will also ==nullptr and vice versa.

Uses of NULL other than comparing with a pointer (like using it to represent the nul byte at the end of a string) won't work with nullptr.

In some cases, NULL is #define NULL 0, as the integer constant 0 is special-cased in C and C++ when you compare it with pointers. This non-type type information causes some problems in both C and C++, so in C++ they decided to create a special type and value that does the same thing in the "proper" use cases, and reliably fails to compile in most of the "improper" use cases.

Insofar as your C++ implementation is compatible with the C implementation you are interoping with (very rare for this not to be true), everything should work.


To be very clear, if ptr is any kind of pointer, then the following expressions are equivalent in C++:

ptr == nullptr
ptr == NULL
ptr == 0
!ptr

As are the following:

ptr = nullptr
ptr = NULL
ptr = 0

and if X is some type, so are the following statements:

X* ptr = nullptr;
X* ptr = NULL;
X* ptr = 0;

nullptr differs when you pass it to a template function that deduces type (NULL or 0 become an int unless passed to an argument expecting a pointer, while nullptr remains a nullptr_t), and when used in some contexts where nullptr won't compile (like char c = NULL;) (note, not char* c=NULL;)

Finally, literally:

NULL == nullptr

is true.

The NULL constant gets promoted to a pointer type, and as a pointer it is a null pointer, which then compares equal to nullptr.


Despite all this, it isn't always true that:

 foo(NULL)

and

 foo(nullptr)

do the same thing.

void bar(int) { std::cout << "int\n"; }
void bar(void*) { std::cout << "void*\n"; }
template<class T>
void foo(T t) { bar(t); }
foo(NULL);
foo(nullptr);

this prints int for NULL and void* for nullptr.

🌐
Reddit
reddit.com › r/cpp_questions › what is the difference between null and nullptr when using them for something like a binary search tree? are those interchangeable?
r/cpp_questions on Reddit: What is the difference between NULL and nullptr when using them for something like a Binary Search Tree? Are those interchangeable?
June 29, 2021 -

As far as I know, NULL is just another name for 0 (edit 3: I used the NULL from <iostream>)for which nullptr is a pointer pointing 0. Some references I have used NULL, but others have nullptr. They are writing their trees in different ways so I am not sure if they are interchangeable, but I saw someone on an overflow post saying that versions of C++ do consider NULL == nullptr. But my past experiences are saying that int *some operator here* pointer is a mess. Can anyone clear this up for me? Thank you!

edit:sample for NULL:TreeNode *leftPtr = NULL;TreeNode *rightPtr = NULL;

sample for nullptr:TreeNode *leftPtr = nullptr;TreeNode *rightPtr = nullptr;// idk if these work, or if they only work if:// for example rootPtr->rightPtr = nullptr

// edit 2: running this, it prints "1" so it must be true,

#include <iostream>

using namespace std;

int main() {
    cout << (NULL == nullptr) << endl;
    return 0;
}

Top answer
1 of 5
9
As far as I know, NULL is just another name for 0 It is not. If you look here , you will see that NULL is defined in all of: It is also defined in all of: You'll also find NULL defined in a lot of 3rd party libraries. And in all instances it is IMPLEMENTATION DEFINED. It's not at all unreasonable to find #define NULL ((void*)(0)) or #define NULL ((char*)(0)) or any other such nonsense, both of which are both INCORRECT AND NOT THE SAME THING. Problems arose when, for a misplaced sense of brevity, K&R decided to reuse integer zero in a different context, where null doesn't mean the same thing. I guess this saved them some punch card space, but it introduced a lot of misunderstanding and conflation of what both null and pointers are, and we've been dealing with this confusion as a source of bugs and exploits ever since. Then Bjarne admits he made the same mistake when declaring pure virtual methods as equal to zero. There are many scenarios that can arise where you mean an integer and get a null pointer, or want a null pointer and get an integer. nullptr is type safe. Never use NULL, there is no scenario where it is necessary or preferred, not even for backward compatibility or when interfacing with a C library.
2 of 5
7
nullptr is the null pointer literal introduced with c++11. It has implicit conversion to any pointer type. It's a keyword in c++. NULL is an implementation-defined null pointer constant, defined in a number of different headers (and I guess pulled in indirectly through your implementation of the iostream header).
🌐
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
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › extensions › nullptr-cpp-component-extensions
nullptr (C++/CLI and C++/CX) | Microsoft Learn
June 25, 2025 - The __nullptr keyword is a Microsoft-specific keyword that has the same meaning as nullptr, but applies to only native code. If you use nullptr with native C/C++ code and then compile with the /clr compiler option, the compiler cannot determine ...
🌐
Medium
medium.com › @pauljlucas › nullptr-in-c23-571782008dad
nullptr in C23. The new nullptr keyword in C23. | by Paul J. Lucas | Medium
July 8, 2025 - To fix these problems, C23 borrowed the nullptr keyword from C++ that’s a literal for the null pointer.
Find elsewhere
🌐
Embedded Artistry
embeddedartistry.com › home › blog › migrating from c to c++: null vs nullptr
Migrating from C to C++: NULL vs nullptr - Embedded Artistry
December 15, 2021 - As I mentioned above, the general rule of thumb that I recommend is that you should start using nullptr whenever you would have used NULL in the past. As a reminder, since C++11, NULL can be either an integer literal with value zero, or a prvalue of type std::nullptr_t.
🌐
Hacker News
news.ycombinator.com › item
> But does C need a nullptr keyword? Yes, it does. > If you're programming in C,... | Hacker News
May 16, 2023 - That was also the usual pattern in C++ when there was no alternative. Once nullptr was introduced in C++, NULL or 0 quickly became a code smell · C++'s type system is far from insane. It's actually one of it's killer features
🌐
Hacker News
news.ycombinator.com › item
I see that after 50 years, C has finally gained an *official* null pointer value... | Hacker News
March 19, 2023 - That wouldn't be so interesting, but it highlights the complexity of specifying a language and implementing a specification. For what sounds at first hearing a lot like "#define nullptr 0" the Clang release notes identify 7 syntactic cases where the C standard and the C++ standard disagree ...
🌐
Open-std
open-std.org › jtc1 › sc22 › wg14 › www › docs › n3042.htm
Introduce the nullptr constant
July 22, 2022 - Since more than a decade C++ has already replaced the problematic definition of NULL which might be either of integer type or void*. By using a new constant nullptr, they achieve a more constrained specification, that allows much better diagnosis of user code.
🌐
W3Schools
w3schools.com › c › c_null.php
C NULL
NULL is a special value that represents a "null pointer" - a pointer that does not point to anything.
🌐
Reddit
reddit.com › r/c_programming › [c23] the addition of nullptr and nullptr_t is bad
r/C_Programming on Reddit: [C23] The addition of nullptr and nullptr_t is bad
October 1, 2023 - Jens’ proposal, in my mind, was to satisfy a semantic construction that the language did not support in any form: generic selection on the type of a nullptr in a way that provides consistent, portable safety. It’s unfortunate that this complicates the language, IMO if NULL had a fixed representation when it was conceived, this wouldn’t exist…
🌐
GNU
gnu.org › software › gnulib › manual › html_node › nullptr.html
nullptr (GNU Gnulib)
Next: static_assert, Previous: bool, Up: ISO C Keyword Substitutes [Contents][Index] ... The nullptr module arranges for nullptr to act like standard C and C++.
🌐
cppreference.com
en.cppreference.com › cpp › types › nullptr_t
std::nullptr_t - cppreference.com
August 11, 2024 - sizeof(std::nullptr_t) is equal to sizeof(void *). The C++ standard requires <stddef.h> to place the contents of <cstddef> in the global namespace, and thereby requires nullptr_t to be available in the global namespace when <stddef.h> is included.
🌐
IBM
ibm.com › docs › en › zos › 2.5.0
Null pointers - IBM Documentation
April 28, 2023 - A null pointer constant is an integer constant expression that evaluates to zero. For example, a null pointer constant can be 0, 0L, or such an expression that can be cast to type (void *)0. C++11 defines a new null pointer constant nullptr ...
🌐
Wikipedia
en.wikipedia.org › wiki › Null_pointer
Null pointer - Wikipedia
June 13, 2026 - The preprocessor macro NULL is ... ((void*)0), the integer value 0 converted to the type void* (see pointer to void type). Since C23, a null pointer is represented with nullptr which is of type nullptr_t (first introduced to C++11), providing a type safe null point...
🌐
DEV Community
dev.to › pauljlucas › nullptr-in-c23-1cn6
nullptr in C23 - DEV Community
July 8, 2025 - To fix these problems, C23 borrowed the nullptr keyword from C++ that’s a literal for the null pointer.
🌐
cppreference.com
en.cppreference.com › cpp › language › nullptr
nullptr, the pointer literal (since C++11) - cppreference.com
August 12, 2024 - The keyword nullptr denotes the pointer literal. It is a prvalue of type std::nullptr_t. There exist implicit conversions from nullptr to null pointer value of any pointer type and any pointer to member type.
🌐
DZone
dzone.com › articles › what-exactly-nullptr-is-in-c
What Exactly Nullptr Is in C++?
April 16, 2020 - This way, by leveraging template functionality, we are actually creating the appropriate type of null pointer every time we do a new type assignment. As nullptr is an integer literal with value zero, you can not able to use its address, which we accomplished by deleting and operator.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › cpp › nullptr
nullptr | Microsoft Learn
August 3, 2021 - If your code might be compiled by using the /clr compiler option, which targets managed code, then use __nullptr in any line of code where you must guarantee that the compiler uses the native C++ interpretation.