How is it a keyword and an instance of a type?

This isn't surprising. Both true and false are keywords and as literals they have a type ( bool ). nullptr is a pointer literal of type std::nullptr_t, and it's a prvalue (you cannot take the address of it using &).

  • 4.10 about pointer conversion says that a prvalue of type std::nullptr_t is a null pointer constant, and that an integral null pointer constant can be converted to std::nullptr_t. The opposite direction is not allowed. This allows overloading a function for both pointers and integers, and passing nullptr to select the pointer version. Passing NULL or 0 would confusingly select the int version.

  • A cast of nullptr_t to an integral type needs a reinterpret_cast, and has the same semantics as a cast of (void*)0 to an integral type (mapping implementation defined). A reinterpret_cast cannot convert nullptr_t to any pointer type. Rely on the implicit conversion if possible or use static_cast.

  • The Standard requires that sizeof(nullptr_t) be sizeof(void*).

Answer from Johannes Schaub - litb on Stack Overflow
🌐
cppreference.com
en.cppreference.com › cpp › language › nullptr
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.
🌐
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).
Discussions

c++ - What is the nullptr keyword, and why is it better than NULL? - Stack Overflow
We now have C++11 with many new features. An interesting and confusing one (at least for me) is the new nullptr. Well, no need anymore for the nasty macro NULL. int* x = nullptr; myclass* obj = n... More on stackoverflow.com
🌐 stackoverflow.com
Help understanding when to use nullptr
I’m working on a library for the esp32 platform using C++ and PlatformIO , and I’m a bit confused about when to use nullptr within functions. If I take a pointer as a parameter, do I need to set it to nullptr at the end of the function, or is it not instantiated inside the function? example: ... More on forum.level1techs.com
🌐 forum.level1techs.com
0
0
December 28, 2018
Convincing other developers to use nullptr over NULL
No point arguing about it, its the objectively better option. I don't understand why he would insist on using NULL. If he really doesn't want to change his habits just for habits sake, i'd actively consider configuring pull requests to automatically run clang-tidy with modernize-use-nullptr -fix. He doesn't have to change his habits in this case, but it will be nullptr henceforth. More on reddit.com
🌐 r/cpp_questions
79
36
June 10, 2024
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
Top answer
1 of 15
460

How is it a keyword and an instance of a type?

This isn't surprising. Both true and false are keywords and as literals they have a type ( bool ). nullptr is a pointer literal of type std::nullptr_t, and it's a prvalue (you cannot take the address of it using &).

  • 4.10 about pointer conversion says that a prvalue of type std::nullptr_t is a null pointer constant, and that an integral null pointer constant can be converted to std::nullptr_t. The opposite direction is not allowed. This allows overloading a function for both pointers and integers, and passing nullptr to select the pointer version. Passing NULL or 0 would confusingly select the int version.

  • A cast of nullptr_t to an integral type needs a reinterpret_cast, and has the same semantics as a cast of (void*)0 to an integral type (mapping implementation defined). A reinterpret_cast cannot convert nullptr_t to any pointer type. Rely on the implicit conversion if possible or use static_cast.

  • The Standard requires that sizeof(nullptr_t) be sizeof(void*).

2 of 15
141

Why nullptr in C++11? What is it? Why is NULL not sufficient?

C++ expert Alex Allain says it perfectly here (my emphasis added in bold):

...imagine you have the following two function declarations:

void func(int n); 
void func(char *s);
 
func( NULL ); // guess which function gets called?

Although it looks like the second function will be called--you are, after all, passing in what seems to be a pointer--it's really the first function that will be called! The trouble is that because NULL is 0, and 0 is an integer, the first version of func will be called instead. This is the kind of thing that, yes, doesn't happen all the time, but when it does happen, is extremely frustrating and confusing. If you didn't know the details of what is going on, it might well look like a compiler bug. A language feature that looks like a compiler bug is, well, not something you want.

Enter nullptr. In C++11, nullptr is a new keyword that can (and should!) be used to represent NULL pointers; in other words, wherever you were writing NULL before, you should use nullptr instead. It's no more clear to you, the programmer, (everyone knows what NULL means), but it's more explicit to the compiler, which will no longer see 0s everywhere being used to have special meaning when used as a pointer.

Allain ends his article with:

Regardless of all this--the rule of thumb for C++11 is simply to start using nullptr whenever you would have otherwise used NULL in the past.

(My words):

Lastly, don't forget that nullptr is an object--a class. It can be used anywhere NULL was used before, but if you need its type for some reason, it's type can be extracted with decltype(nullptr), or directly described as std::nullptr_t, which is simply a typedef of decltype(nullptr), as shown here:

Defined in header <cstddef>:

See:

  1. https://en.cppreference.com/w/cpp/types/nullptr_t
  2. and https://en.cppreference.com/w/cpp/header/cstddef
namespace std
{
typedef decltype(nullptr) nullptr_t; // (since C++11)
// OR (same thing, but using the C++ keyword `using` instead of the C and C++ 
// keyword `typedef`):
using nullptr_t = decltype(nullptr); // (since C++11)
} // namespace std

References:

  1. Cprogramming.com: Better types in C++11 - nullptr, enum classes (strongly typed enumerations) and cstdint
  2. https://en.cppreference.com/w/cpp/language/decltype
  3. https://en.cppreference.com/w/cpp/types/nullptr_t
  4. https://en.cppreference.com/w/cpp/header/cstddef
  5. https://en.cppreference.com/w/cpp/keyword/using
  6. https://en.cppreference.com/w/cpp/keyword/typedef
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › understanding-nullptr-c
Understanding nullptr in C++ - GeeksforGeeks
However, its use can lead to ambiguity ... these issues, C++11 introduced nullptr, a type-safe keyword that clearly represents a null pointer and eliminates ambiguity in pointer operations....
Published: June 9, 2026
🌐
Medium
medium.com › @weidagang › modern-c-nullptr-fa494808d31a
Modern C++: nullptr. Saying Goodbye to NULL | by Dagang Wei | Medium
June 24, 2024 - C++ has evolved significantly over the years, and one of the most welcome additions in C++11 is the introduction of nullptr. If you're still using NULL or the integer 0 for null pointers in your C++ code, it's time for an upgrade.
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 - A null pointer constant may be implicitly converted to any pointer type; such conversion results in the null pointer value of that type. If a null pointer constant has integer type, it may be converted to a prvalue of type std::nullptr_t.
🌐
Wikipedia
en.wikipedia.org › wiki › Null_pointer
Null pointer - Wikipedia
June 13, 2026 - The preprocessor macro NULL is ... 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 pointer....
🌐
DZone
dzone.com › articles › what-exactly-nullptr-is-in-c
What Exactly Nullptr Is in C++?
April 16, 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 an integer literal that evaluates to zero.
🌐
Open-std
open-std.org › jtc1 › sc22 › wg14 › www › docs › n3042.htm
Introduce the nullptr constant
July 22, 2022 - The idea of nullptr is to end this ambiguity and to provide a keyword with a value and a portable type that can be used anywhere where a null pointer constant is needed.
🌐
YouTube
youtube.com › shorts › lfRVyljBMu8
Why C++ replaced NULL with nullptr - YouTube
Learn about why C++ introduced the nullptr keyword. nullptr implicitly converts to pointer types, but not to other types like int. This resolves some ambigui...
Published: February 19, 2026
🌐
cppreference.com
en.cppreference.com › cpp › keyword › nullptr
C++ keyword: nullptr (since C++11) - cppreference.com
nullptr pointer literal · Support us · Recent changes · FAQ · Offline version · What links here · Related changes · Upload file · Special pages · Printable version · Permanent link · Page information · In other languages · Deutsch · Español · Français · Italiano ·
🌐
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.
🌐
Codecademy
codecademy.com › docs › c++ › pointers › nullptr
C++ (C Plus Plus) | Pointers | nullptr | Codecademy
November 20, 2024 - Represents a null pointer in C++, ensuring type safety and indicating that a pointer does not point to any valid memory location.
🌐
Etlcpp
etlcpp.com › nullptr.html
nullptr
Sorry, the page you are looking for doesn't exist
🌐
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
🌐
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.
🌐
Draft C++ Standard
eel.is › c++draft › support.types.nullptr
[support.types.nullptr]
Although nullptr's address cannot be taken, the address of another nullptr_t object that is an lvalue can be taken.
🌐
Steam
store.steampowered.com › app › 1579650 › NULLPTR
Save 33% on NULLPTR on Steam
NULLPTR - NULLPTR is a real-time tactical hacking puzzle, nominated as a finalist for Innovation and Best Brazilian Game at Gamescom LATAM 2024, where every action you take reshapes the challenge ahead.
Price: $10.04
🌐
Level1Techs
forum.level1techs.com › dev zone › code
Help understanding when to use nullptr - Code - Level1Techs Forums
December 28, 2018 - I’m working on a library for the esp32 platform using C++ and PlatformIO , and I’m a bit confused about when to use nullptr within functions. If I take a pointer as a parameter, do I need to set it to nullptr at the end of the function, or is it not instantiated inside the function? example: void func(uint32_t* value) { if (*value