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.
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
[C++] Difference between null and nullptr
They mean the same thing. nullptr is part of the language (as of c++11), whereas NULL was just a macro that turns into the number 0. 90% of the time, they're totally interchangeable. Good modern C++ code should always use nullptr, but older code will use NULL and it will work fine. There are a few cases where nullptr is better. Suppose you have a function that can take either an int or a pointer: void Create(int count); // Creates this many enemies void Create(Enemy* clone); // Create one enemy, with an optional enemy to clone (may be nullptr) If you call Create(NULL), it will actually call the first version, which is not what you want. That's because NULL is just 0, which is an int. If you call Create(nullptr), it knows you want to call the second version. More on reddit.com
🌐 r/learnprogramming
4
0
December 12, 2018
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
🌐
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 - For example, it is valid to assign an integer to NULL - despite not being a pointer. Alternatively, NULL will be an integer type in templates whereas nullptr will be a unique type (std::nullptr_t) - which can also be overloaded on (e.g.
🌐
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.
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.

🌐
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....
🌐
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.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › understanding-nullptr-c
Understanding nullptr in C++ - GeeksforGeeks
Unlike NULL, nullptr cannot be assigned to integer types.
Published   4 days ago
🌐
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.
🌐
Medium
medium.com › @weidagang › modern-c-nullptr-fa494808d31a
Modern C++: nullptr. Saying Goodbye to NULL | by Dagang Wei | Medium
June 24, 2024 - It has its own distinct type (std::nullptr_t), ensuring type safety and eliminating the ambiguity associated with NULL and 0. int* ptr = nullptr; // Clear indication of a null pointer
🌐
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.
🌐
Reddit
reddit.com › r/learnprogramming › [c++] difference between null and nullptr
r/learnprogramming on Reddit: [C++] Difference between null and nullptr
December 12, 2018 -

Flocked straight here because the toxic stack overflow has the biggest trigger finger when it comes to marking posts as duplicates.

But anywho.

I had an examination recently, and I remember one of the theory questions asking what the difference is between null and nullptr in c++. I was unsure and didn't know how to answer it, for future reference could someone please explain to me what differs between the two.

Top answer
1 of 2
2
They mean the same thing. nullptr is part of the language (as of c++11), whereas NULL was just a macro that turns into the number 0. 90% of the time, they're totally interchangeable. Good modern C++ code should always use nullptr, but older code will use NULL and it will work fine. There are a few cases where nullptr is better. Suppose you have a function that can take either an int or a pointer: void Create(int count); // Creates this many enemies void Create(Enemy* clone); // Create one enemy, with an optional enemy to clone (may be nullptr) If you call Create(NULL), it will actually call the first version, which is not what you want. That's because NULL is just 0, which is an int. If you call Create(nullptr), it knows you want to call the second version.
2 of 2
1
nullptr - A literal of type std::nullptr_t, used to represent a null pointer, or a pointer that doesn't point to anything. NULL - Post C++11, this is a macro for nullptr. Before C++11, this was the constant 0. In C it could also be (void*)0. Regardless, it's also intended to represent a null pointer. You should generally use nullptr instead whenever possible. 0 - In C, and therefore C++ for compatibility reasons, assigning this to a pointer will cause the pointer to be null, meaning it doesn't point to anything. The actual value stored in the pointer need not be the literal bits 0x0000000 (historically, many systems have used other representations for null), but that's what it is on most modern systems. '\0' aka "nul" - this is the null character, a special non-printable control character, often used to designate the end of a string. std::nullopt - used to represent the null case in a std::optional. This is a nullable type, meaning it can have a state where it holds no value at all (which is different than 0, which is itself a value).
🌐
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 - So the C++ committee apparently decided to dictate how to implement the NULL macro by requiring that the NULL macro must be defined as 0. However if they had left it alone then the compiler writers could have created their own nullptr equivalent instead of being forced to complicate their already non-trivial type-promotion code to allow 0 constants to be promoted to pointers.
🌐
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.
🌐
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 ...
🌐
Cppreference
en.cppreference.com › w › cpp › language › nullptr.html
nullptr, the pointer literal (since C++11) - cppreference.com
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.
🌐
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.
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.