🌐
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.
🌐
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 › [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 - No need for nullptr. ... An issue the Committee fails to ignore with various implementation-defined things is that choices allowed for some things would allow implementations to avoid problems associated with others. For example, on an implementation which defined NULL as 0, and used a different representation for passing null pointers and integer zeros to variadic function, code which passed NULL to a variadic function would fail.
🌐
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).
🌐
Reddit
reddit.com › r/cpp_questions › o, null and nullptr. what to use where?
r/cpp_questions on Reddit: O, null and nullptr. What to use where?
September 30, 2014 -

I am unsure what the difference is as null and 0 should be the same on bit level. Are there any real differences seen from the hardware or are they just renaming the same value?

Further, when should I use null if nullptr exists?

🌐
Reddit
reddit.com › r/cpp_questions › ¿cuál es la diferencia entre null y nullptr en cpp ??
r/cpp_questions on Reddit: ¿Cuál es la diferencia entre NULL y nullptr en cpp ??
March 20, 2021 - Alternativamente, NULL será un tipo entero en plantillas, mientras que nullptr será un tipo único (std::nullptr_t), que también se puede sobrecargar (por ejemplo, funciones de punteros inteligentes).
🌐
Reddit
reddit.com › r/cpp › when msdn says null, is it okay to use nullptr?
r/cpp on Reddit: When MSDN says NULL, is it okay to use nullptr?
March 7, 2018 - We called a C-based varargs function from C++ which used NULL as a sentinel value... which led to crashes in 64-bit mode since the null pointer was then a different size from an int. ... The Standard permits NULL to be a macro for nullptr.
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 - 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 › convincing other developers to use nullptr over null
r/cpp_questions on Reddit: Convincing other developers to use nullptr over NULL
June 10, 2024 -

Not sure whether this is more appropriate for r/cpp, but I thought I'd ask here first.

I always use nullptr over NULL, for the reason that overload resolution with NULL can lead to surprising outcomes because it's an integer, and not a pointer. (also it's shiny and "modern", or it can be considered more idiomatic C++, I guess)

So I'm working with a new team member who is not convinced. He thinks this reason is really obscure and that you will rarely, if ever, encounter a real life scenario where that reason comes into play. I couldn't come up with an organic scenario that could happen in real code, and to be honest - I don't think I've seen something like that in the wild.

Would you insist on strictly using nullptr in your codebase? I keep seeing him use NULL in his pull requests and I'm starting to wonder if I should stop being the "code police" and give up on this battle.

🌐
Reddit
reddit.com › r/programming › use nullptr instead of null from now on
r/programming on Reddit: Use nullptr instead of NULL from now on
January 15, 2016 - Yet so many people use NULL still... ... Create your account and connect with a world of communities.
🌐
Reddit
reddit.com › r/learnprogramming › what’s with all these 0s, nullptrs, nuls, and nulls in c++, and what's the difference between them? can anybody eli5?
r/learnprogramming on Reddit: What’s with all these 0s, nullptrs, NULs, and NULLs in C++, and what's the difference between them? Can anybody ELI5?
May 7, 2016 -

I'm sorry if this question is stupid or trivial.

We’ve got NULL, which is an int 0 but not all bits 0 (how is that???), an ASCII ‘\0’ NUL, which apparently converts to NULL automatically but is somehow different, and then there’s std::nullptr_s etc. What’s the difference? Why can’t we have just one 0 instead of all these NULs, NULLs, 0s, all-bit-zeros, etc.?

Can anybody explain the intuition behind the concept of the NULL pointer and the rest of the 0s? Why isn’t there just one zero that works everywhere and means the same thing?

Top answer
1 of 3
15
A null pointer is a pointer that specifically points to nothing. It's not a garbage value. So, syntactically, there must be some way provided for the programmer to specify such a value. That way is to use a literal 0. When the compiler sees that where it expects a pointer value, it generates whatever bit pattern represents a null pointer on that platform. It may not be all bits 0. Apparently, using 0 was not considered clear enough, so the macro NULL was introduced in C, and was defined to be ((void *) 0). Because converting from void * to any other pointer type is implicit, one could write: char *p = NULL; This mostly worked okay, and is what NULL is usually defined as in C. Then C++ came along, and introduced operator overloading. Also, it made sense for C++ to be more strictly typed. So C++ removed the implicit conversion from void *. Now: char *p = NULL; would no longer compile if NULL were defined to be ((void *) 0). So NULL is 0 in C++. But this doesn't work well for overloading. If one has: void foo(int); void foo(char *); ... foo(NULL); then this will call foo(int). So nullptr was introduced, which is a special keyword object of type std::nullptr_t. The compiler knows that it means null pointer, always, so there are no ambiguous/mistaken situations. (ASCII NUL is completely different and unrelated.) So much of it is historical. If you are programming in C++, just use nullptr.
2 of 3
4
The null character and the null pointer are two completely different and unrelated things. Historically speaking, there were two ways to refer to the null pointer: 0 and NULL. The latter was usually just a #define for the former. But the problem is that 0 is also an integer literal. So this same literal led a dual life. It could be either an integer or a pointer depending on context. That's no good, because there are situations where it leads to ambiguity. C++11 introduced a proper solution to the problem, which is nullptr, a value of type nullptr_t. This cannot be mistaken for an integer. So in modern C++, if you want to refer to the null pointer, you should write nullptr, and never 0 or NULL. It's quite simple. The null character is something entirely different. It's a character with value zero. As characters are just a type of integer, the integer literal 0 can be used to refer to the null character as well, just as the integer literal 32 can be used to refer to the space character, if you really wanted to. Of course you can also write ' ' to refer to the space character, just as you can write '\0' to refer to the null character. Again, and I can't stress this enough, these have absolutely nothing to do with the null pointer. So if you ever see someone doing something like char c = NULL; That is garbage. Don't do that. It may compile due to the complicated history of the language, but it's completely wrong. nullptr solves this problem, because char c = nullptr; will rightfully fail to compile. In summary, nullptr solves all problems.
🌐
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.
🌐
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 - 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.
🌐
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 ...
🌐
Reddit
reddit.com › r/learnprogramming › trying to understand null pointers
r/learnprogramming on Reddit: Trying to understand NULL pointers
December 30, 2021 -

Hello all again,

I have another stupid question here lol, so I'm trying to wrap my head around NULL. Im currently under the impression that NULL is a built in constant that has a value of zero, but what does that actually mean? When would it be appropriate to use null? If someone could explain it in layman's terms that would be super helpful!