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

🌐
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.
🌐
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).
🌐
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.
🌐
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 ...
Find elsewhere
🌐
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
cppreference.net › c › language › nullptr.html
Predefined null pointer constant (since C23) - cppreference.net
The keyword nullptr denotes a predefined null pointer constant. It is a non-lvalue of type nullptr_t.
🌐
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…
🌐
cppreference.com
en.cppreference.com › c › types › nullptr_t
nullptr_t - cppreference.com
nullptr_t is the type of the predefined null pointer constant, nullptr. It is a distinct type that is not itself a pointer type. It can be implicitly converted to any pointer type or bool, and the result is the null pointer value of that type or false respectively.
🌐
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
🌐
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.
🌐
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.
🌐
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 ...
🌐
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++.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › understanding-nullptr-c
Understanding nullptr in C++ - GeeksforGeeks
Explanation: A null pointer evaluates to false in a conditional expression, while a valid pointer evaluates to true. The nullptr keyword supports safe and well-defined comparisons with pointer types.
Published: June 9, 2026
🌐
Handmade Network
hero.handmade.network › forums › code-discussion › t › 1292-null_define_in_c__c_differs!
NULL Define in c & c++ differs?! | Handmade Network
June 14, 2016 - 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.