TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  OAL#015Checked automatically with code checker

This rule is Obsolete
Synopsis:Use nullptr instead of 0 or NULL for pointers
Severity Level:6
Category:Object Allocation


The keyword "nullptr" denotes the null pointer. It has been introduced in C++11 to replace all other, less elegant ways to denote the null pointer such as NULL and 0. nullptr is preferred to NULL and 0 because it improves type safety and avoids ambiguous situations. An ambigious situation for the old null pointer type is shown below:

void f(char const *ptr);
void f(int v);

f(NULL);  //which function will be called?

Wrong examples:

ptr = 0;
if (ptr == NULL) { ... }

Right examples:

ptr = nullptr;
if (ptr == nullptr) { ... }