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 literalAll lessons in this course
- Raw Pointers and the Address-of Operator
- Dereferencing and Pointer Arithmetic
- nullptr and Null Pointer Safety
- When to Use Pointers vs References