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]
- [1] GCC page about C++0x support
- [2] Scott Meyers. C++ And Beyond 2012 session: 'Initial thoughts on Effective C++11'. 2012. 'Prefer nullptr to NULL and 0'
- [3] Jason Turner, cppbestpractices: Use nullptr