int* p1 = nullptr;
int* p2 = NULL;
int* p3 = 0;
p2 == p1; // true
p3 == p1; // true
int* p {}; // p is set to nullptr
void foo(int);
foo(0); // calls foo(int)
foo(NULL); // calls foo(int)
foo(nullptr); // compile time error
void bar(int);
void bar(void*);
void bar(std::nullptr_t);
bar(0); // calls bar(int)
bar(NULL); // calls bar(int) if NULL is 0, may be ambiguous if NULL is 0L
bar(nullptr); // calls bar(std::nullptr_t) if provided, bar(void*) otherwise
-
value for a pointer that points to nothing
-
more expressive and safer than
NULL/0 constant
-
has defined type
std::nullptr_t
-
solves the problem with overloaded functions taking a pointer or an integer as an argument