Difference between NULL and nullptr in c plus plus

difference between NULL and nullptr in c++ 

NULL

  1. It is not defined by c++.
  2. It is internally mapped to into(zero).

Example

int f1 (char*);

int f1 (int);

char*ptr = NULL; // pointer

if  we have a NULL pointer then function call  int f1 (cptr) would always map to  f1(int) and not to int f1 (char*).

 

nullptr

  1. It has been defined by c++.
  2. nullptr is a legal empty/ null pointer.

Example

int f1 (char*);

int f1 (int);

char*ptr = nullptr; // pointer

if  we have a nullptr pointer then function call  int f1 (cptr)  will map to   int f1 (char*) only.

You May Also Like