Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 707 Bytes

nullptr.cpp11.adoc

File metadata and controls

43 lines (30 loc) · 707 Bytes

nullptr

Value for pointer that do not point anywhere

It is a type-safe version of NULL, it converts to any pointer, but not to integral types.

Has a separate type: std::nullptr_t

#include <cstddef>

void foo(int);

foo(0); // calls foo(int)
foo(NULL); // calls foo(int), probably an error
foo(nullptr); // compile-time error

nullptr

#include <cstddef>

void foo(int);
void foo(int*);

foo(0);       // foo(int)
foo(NULL);    // depends on compiler, ambiguos
foo(nullptr); // foo(int*)
int i;
i = 0;
i = NULL;    // probably an error
i = nullptr; // compile-time error