Before C++11, the only way to refer to a null pointer was by using the integer literal 0
, which created ambiguity about whether a
pointer or an integer was intended. Even with the NULL
macro, the underlying value is still 0
.
C++11 introduced the keyword nullptr
, which unambiguously refers to the null pointer. It should be used systematically.
void f(char *c);
void g(int);
void usage()
{
f(0); // Noncompliant
f(NULL); // Noncompliant
f(nullptr); // Compliant: unambiguous
g(0); // Compliant, a real integer
// g(nullptr); // This would not compile
}