Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 958 Bytes

CppNullptr.md

File metadata and controls

33 lines (24 loc) · 958 Bytes

nullptr is a C++11 keyword to indicate an unitialized pointer.

#include <cassert>

int main()
{
  //Create a new p
  int * p = new int(3);
  assert(*p == 3);

  //Get rid of the current p
  delete p;
  p = nullptr;

  //Create a new p
  p = new int(4);
  assert(*p == 4);
}
  • Prefer nullptr to NULL and 0 [2,3]