Start here · Essential guide
NULL vs nullptr in C++
NULL is an older macro, usually defined as 0. nullptr, added in C++11, is a typed null pointer that avoids overload surprises. Here's how to choose.
Strings, Containers and Memory
Why C++ added nullptr, how it differs from NULL and 0 and what null pointers are.
Start here · Essential guide
NULL is an older macro, usually defined as 0. nullptr, added in C++11, is a typed null pointer that avoids overload surprises. Here's how to choose.
In C, 0 == NULL is true because both are null pointer constants. Here is why the comparison works, what NULL expands to, and what to watch for.
Deleting a nullptr in C++ does nothing and is safe, so no if check is needed. Learn why delete ignores null pointers and why deleting twice is a bug.
A null pointer in C points to no object or function. Learn how NULL and 0 create one, how to test for it, and why dereferencing it is undefined behavior.
NULL and 0 can both mark a null pointer, but NULL shows the intent. A plain 0 can cause trouble in variadic calls and with C++ overloads.
Related topics