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 - Since C++11, NULL can be either an integer literal with value zero, or a prvalue of type std::nullptr_t. Because of this ambiguity, I recommend switching exclusively to nullptr.
๐ŸŒ
Reddit
reddit.com โ€บ r/cpp_questions โ€บ what is the difference between null and nullptr in cpp ??
r/cpp_questions on Reddit: What is the difference between NULL and nullptr in cpp ??
March 20, 2021 - So, in short, the difference is that NULL is numerical zero, nullptr is pointer zero. ... BZZT. Wrong. NULL has to evaluate to a null pointer constant which can EITHER be an integral zero (it can't be just any old unused number) or the nullptr.
Discussions

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
NULL Define in c & c++ differs?! | Handmade Network
Your example doesn't really apply to the case of void pointers, since we cannot do pointer arithmetic with void pointers. The discussion is about the concept of null pointers and the value of 0, not necessarily the type of the integer constant 0. I don't see how 0, nullptr, NULL or ((void*)0) ... More on hero.handmade.network
๐ŸŒ hero.handmade.network
June 16, 2016
c++ - Should I cast comparisons to NULL or nullptr? - Software Engineering Stack Exchange
Adding the cast to every use of nullptr seems like it would make the code more cluttered/harder to read. I haven't seen much (if any) code that does so. Number 2 isn't a good reason in and of itself, so I'm wondering if it's done because it's more convenient for the code author and/or if it's because there really is no compelling reason to do so. ... If I'm stuck with C++03 now but still want to plan for C++11 in the future, is the best option to stick with legacy NULL ... More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
December 12, 2017
What is the difference between NULL and nullptr in cpp ??
nullptr is a keyword denoting universal null pointer value suitable for implicit convetion to any pointer type. NULL is a macro that is implementation defined and as with many macros, its text replacement may not correctly be interpreted, especially in templates. NULL may also fall into unwanted implicit convertions. More on reddit.com
๐ŸŒ r/cpp_questions
18
5
March 20, 2021
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.

๐ŸŒ
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 constantโ€ (a [code ]#define[/code] of C) thatโ€™s actually an integer that can be assigned to a pointer 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.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 3097671 โ€บ null-vs-nullptr
NULL vs nullptr | Sololearn: Learn to code for FREE!
The difference is that NULL is an integer, nullptr is a pointer type. It is a crucial difference when dealing with (resolving) method overloads. They are not interchangeable*). When you talk pointer, always use nullptr.
๐ŸŒ
University of Waterloo
ece.uwaterloo.ca โ€บ ~dwharder โ€บ icsrts โ€บ C โ€บ 14
NULL vs 0 vs nullptr | University of Waterloo
In the C++-11 standard, they introduced a new representation of a null pointer, namely nullptr which is of type nullptr_t.
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 ...
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ [deleted by user]
[deleted by user] : r/C_Programming
July 23, 2025 - In C, NULL is an implementation-defined value that evaluates to the null pointer constant, possibly cast to void*. nullptr is an explicit null pointer value. As long as you are comparing them to pointers (like the return of fopen), then they are interchangeable.
๐ŸŒ
Cplusplus
cplusplus.github.io โ€บ LWG โ€บ issue1314
Issue 1314: NULL and nullptr
Currently, the 17.2 [support.types]/3 allows NULL to be any null pointer constant. The footnote marks that 0 or 0L might be appropriate. However, this definition also allows the implementation to define NULL to be nullptr.
๐ŸŒ
Medium
medium.com โ€บ @weidagang โ€บ modern-c-nullptr-fa494808d31a
Modern C++: nullptr. Saying Goodbye to NULL | by Dagang Wei | Medium
June 24, 2024 - Maintenance Challenges: The use of NULL and 0 lacked clarity and could make code harder to understand and maintain. nullptr is a keyword in C++ that explicitly represents a null pointer value.
๐ŸŒ
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 - Like void* and 0, nullptr implicitly converts to any type of pointer; unlike NULL, itโ€™s guaranteed to be a pointer.
๐ŸŒ
Handmade Network
hero.handmade.network โ€บ forums โ€บ code-discussion โ€บ t โ€บ 1292-null_define_in_c__c_differs! โ€บ 2
NULL Define in c & c++ differs?! | Handmade Network
June 16, 2016 - Which means that if you want the feature argument dependant lookup to work correctly, you would need to be explicit with your null pointers. So if you are explicitly casting everytime when you use a null pointer, you can just as well use nullptr, which does do the right thing, since it can't be implicitly casted to an int.
๐ŸŒ
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 - But most people would probably prefer you to write NULL or nullptr. As noted, MSDN understands that a significant portion of its readership is not fluent in the subtleties of C and C++. When it writes NULL, it means the obvious thing: A null pointer. You can translate that into the appropriate construction for the language you are using.
๐ŸŒ
HackerNoon
hackernoon.com โ€บ what-exactly-is-nullptr-in-c-94d63y6t
What Exactly Is nullptr in C++ | HackerNoon
April 25, 2020 - NULL is 0(zero) i.e. integer constant zero with C-style typecast to void*, while nullptr is prvalue of type nullptr_t which is integer literal evaluates to zero.
๐ŸŒ
DZone
dzone.com โ€บ articles โ€บ what-exactly-nullptr-is-in-c
What Exactly Nullptr Is in C++? - DZone
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...
๐ŸŒ
Pudn
pudn.club โ€บ programming โ€บ null-vs-nullptr-in-modern-c-plus-plus-what-developers-should-know
NULL vs nullptr in Modern C++: What Developers Should Know ยท Programmers' United Development Network
December 18, 2023 - It can convert to any pointer type. It avoids ambiguity in overload resolution. ... Unlike NULL (integer 0), nullptr has its own type: std::nullptr_t.
Top answer
1 of 1
22

Let's further say that, because of limitations with some of the tools I have that don't support any standards newer than C++03, I have this code in a header:

This is a fantastically bad idea.

The expression (0) is (more or less) equivalent to the C++ definition of the NULL. The thing is, nullptr was invented specifically to deal with shortcomings of the NULL.

Therefore, pretending that they are in some way equivalent will only confuse readers. It will make people used to C++11 write code that has different behavior when compiled on C++03 compilers. For example:

void foo(int);
void foo(Bar*);

foo(nullptr);

C++11 tells us that this must call foo(Bar*). But your C++03 macro will instead call foo(int). Since foo(NULL) would cause the same problem, nullptr was invented to stop that.

So having C++03 code that looks like C++11 code but behaves differently is a terrible idea.

nullptr, by design, pretty much never needs to be cast to a specific pointer type. The only exception is if you're calling some kind of function of the form:

template<typename T>
void foo(T* p);

But even then, you can just use foo<ActualType>(nullptr) and get the same effect as foo(static_cast<ActualType*>(nullptr)).

Your not-nullptr needs casting in the same circumstances that NULL does. Indeed, since it is essentially equivalent to NULL, you should just use NULL. And therefore, you have all of the caveats that NULL has.

And FYI: it's pretty much impossible to create a type in C++03 that has identical behavior to C++11's nullptr_t type. You can get close, by using implicit conversions and so forth. But there will always be corner cases where it doesn't work.

So stop promising nullptr behavior that you cannot ensure.