0Pricing
C++ Academy · Lesson

nullptr and Null Pointer Safety

Use nullptr instead of NULL or 0 and guard against null dereferences.

What is a Null Pointer?

A null pointer is a special value that points to "nothing." Dereferencing it is undefined behavior — usually crashes with a segmentation fault.

nullptr in Modern C++

Since C++11, the keyword nullptr represents a typed null pointer literal. Prefer it over NULL or 0.

int* p1 = nullptr;
int* p2 = NULL;       // legacy macro
int* p3 = 0;          // legacy literal

All lessons in this course

  1. Raw Pointers and the Address-of Operator
  2. Dereferencing and Pointer Arithmetic
  3. nullptr and Null Pointer Safety
  4. When to Use Pointers vs References
← Back to C++ Academy