Jan 2 in C++

nullptr in C++

1 Answer

Jan 2

At last, C++ has a keyword that designates a null pointer constant. nullptr replaces the bug-prone NULL macro and the literal 0 that have been used as null pointer substitutes for many years. nullptr is strongly-typed:

void f(int); //#1

void f(char *);//#2


f(0); //which f is called?


f(nullptr) //unambiguous, calls #2

nullptr is applicable to all pointer categories, including function pointers and pointers to members:

const char *pc=str.c_str(); //data pointers

if (pc!=nullptr)


int (A::*pmf)()=nullptr; //pointer to member function

void (*pmf)()=nullptr; //pointer to function

Click here to read more about C++
Click here to read more about Insurance

Related questions

Jan 2 in C++
Mar 17 in C++
Jul 16, 2019 in C++