nullptr has type std::nullptr_t. It's implicitly convertible to any pointer type. Thus, it'll match std::nullptr_t or pointer types in overload resolution, but not other types such as int.

0 (aka. C's NULL bridged over into C++) could cause ambiguity in overloaded function resolution, among other things:

f(int);
f(foo *);

(Thanks to Caleth pointing this out in the comments.)

Answer from Joe Z on Stack Overflow
🌐
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 - The general rule of thumb that I recommend is that you should start using nullptr whenever you would have used NULL in the past. What’s so wrong with our old friend NULL, anyway? Traditionally, the NULL macro is an implementation defined constant representing a null pointer, usually the integer 0.
🌐
Sololearn
sololearn.com › en › Discuss › 3097671 › null-vs-nullptr
NULL vs nullptr | Sololearn: Learn to code for FREE!
Both are a 64bit zero, but the types are different, and the compiler will care about that difference. ... Peter Nicholas NULL is passing 0 or NULL to mostly an int ( integer )version. And nullptr allows for both pointers and integers, usually ...
Discussions

c++ - NULL vs nullptr (Why was it replaced?) - Stack Overflow
I know that in C++ 0x or NULL was replaced by nullptr in pointer-based applications. I'm just curious of the exact reason why they made this replacement? In what scenario is using nullptr over NULL More on stackoverflow.com
🌐 stackoverflow.com
What is the difference between NULL and nullptr when using them for something like a Binary Search Tree? Are those interchangeable?
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. More on reddit.com
🌐 r/cpp_questions
5
8
June 29, 2021
Is C NULL equal to C++11 nullptr - Stack Overflow
I like to use nullptr instead of NULL. Now I call a C function (from libjansson in this case). NULL in C is implementation defined. For nullptr I found that "A null pointer constant is an integral More on stackoverflow.com
🌐 stackoverflow.com
Equivalent of c++'s NULL or python' s None in MATLAB
Equivalent of c++'s NULL or python' s... Learn more about isempty, isnan More on mathworks.com
🌐 mathworks.com
5
1
May 20, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › understanding-nullptr-c
Understanding nullptr in C++ - GeeksforGeeks
Unlike NULL, nullptr cannot be assigned to integer types.
Published   6 days ago
🌐
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 - For F(NULL), which function gets called depends on how NULL is defined. To fix these problems, C23 borrowed the nullptr keyword from C++ that’s a literal for the null pointer.
🌐
Codecademy
codecademy.com › docs › c++ › pointers › nullptr
C++ (C Plus Plus) | Pointers | nullptr | Codecademy
November 20, 2024 - The nullptr keyword in C++ represents a null pointer, ensuring type safety and clarity in pointer operations. Introduced in C++11, it replaces the traditional NULL macro and eliminates ambiguity in comparisons and function overloads involving ...
🌐
Quora
quora.com › Whats-the-difference-between-NULL-and-nullptr-in-C++
What's the difference between NULL and nullptr in C++? - Quora
Answer (1 of 13): NULL is a “manifest ... because of an implicit conversion. nullptr is a keyword representing a value of self-defined type, that can convert into a pointer, but not into integers....
Find elsewhere
🌐
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 ...
🌐
Java Guides
javaguides.net › 2023 › 12 › difference-between-null-and-nullptr-in-cpp.html
Difference Between null and nullptr in C++
December 18, 2023 - nullptr is a keyword introduced in C++11, representing a null pointer constant, and is meant to replace NULL in modern C++ code.
🌐
Cppreference
en.cppreference.com › w › c › language › nullptr.html
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.
🌐
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
6
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).
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:

Copyptr = nullptr
ptr = NULL
ptr = 0

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

CopyX* 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:

CopyNULL == 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:

Copy foo(NULL)

and

Copy foo(nullptr)

do the same thing.

Copyvoid 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.

🌐
DZone
dzone.com › articles › what-exactly-nullptr-is-in-c
What Exactly Nullptr Is in C++?
April 16, 2020 - ... In such cases, you need explicit ... nullptr is a subtle example of the Return Type Resolver idiom that automatically deduces a null pointer of the correct type depending upon the type of the instance it is assigning to...
🌐
DEV Community
dev.to › pauljlucas › nullptr-in-c23-1cn6
nullptr in C23 - DEV Community
July 8, 2025 - Like void* and 0, nullptr implicitly converts to any type of pointer; unlike NULL, it’s guaranteed to be a pointer.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 835458-equivalent-of-c-s-null-or-python-s-none-in-matlab
Equivalent of c++'s NULL or python' s None in MATLAB - MATLAB Answers - MATLAB Central
May 20, 2021 - You can store it in a single array of pointer type -- and it often is stored that way. For example if you create a common two-level array, like int** for a pointer to an array of pointers to int, then it would be common to set the unused slots to NULL, and there are no class problems in doing that. python None is a different class.
🌐
Handmade Network
hero.handmade.network › forums › code-discussion › t › 1292-null_define_in_c__c_differs!
NULL Define in c & c++ differs?! | Handmade Network
ratchetfreak Why C++ doesn't define NULL as nullptr is because idiot programmers used NULL as the 0 constant, most probably to avoid "magic number" warnings and nullptr doesn't convert to int implicitly so a #define NULL nullptr would break the C compatibility.
🌐
University of Waterloo
ece.uwaterloo.ca › ~dwharder › icsrts › C › 14
NULL vs 0 vs nullptr | University of Waterloo
If you feel you must define NULL, use ... The const qualifier (§5.4) prevents accidental redefinition of NULL and ensures that NULL can be used where a constant is required."
🌐
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.
🌐
Microsoft
devblogs.microsoft.com › dev blogs › the old new thing › when msdn says null, is it okay to use nullptr?
When MSDN says NULL, is it okay to use nullptr? - The Old New Thing
March 13, 2019 - If NULL is defined as (void*)0 in C or as nullptr in C++, then it can be assigned only to a pointer type. And since MSDN cannot control how the C and C++ header files define NULL, it needs to work with any definition that is permitted by the ...