C++ Literals nullptr

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

C++11

A keyword denoting a null pointer constant. It can be converted to any pointer or pointer-to-member type, yielding a null pointer of the resulting type.

Widget* p = new Widget();
delete p;
p = nullptr; // set the pointer to null after deletion

Note that nullptr is not itself a pointer. The type of nullptr is a fundamental type known as std::nullptr_t.

void f(int* p);

template <class T>
void g(T* p);

void h(std::nullptr_t p);

int main() {
    f(nullptr); // ok
    g(nullptr); // error
    h(nullptr); // ok
}


Got any C++ Question?