`nullptr` — C++ Keyword
`nullptr` — C++ Keyword
The nullptr keyword in C++11: a type-safe null pointer constant.
`nullptr` — C++ Keyword
The nullptr keyword in C++11: a type-safe null pointer constant.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
nullptrA type-safe null pointer constant of type std::nullptr_t, introduced in C++11. Replaces the ambiguous NULL macro and the integer literal 0 in pointer contexts.
Type* ptr = nullptr;
if (ptr == nullptr) { ... }
func(nullptr); // unambiguously passes a null pointer, not 0
#include <print>
void process(int* p) {
if (p == nullptr) {
std::println("null pointer");
return;
}
std::println("{}", *p);
}
// Overload resolution: nullptr -> pointer overload, not int overload
void overloaded(int) { std::println("int"); }
void overloaded(int*) { std::println("pointer"); }
int main() {
int x = 42;
process(&x); // 42
process(nullptr); // null pointer
// overloaded(0); // ambiguous
overloaded(nullptr); // unambiguously selects pointer overload
}
nullptr has type std::nullptr_t, which is implicitly convertible to any pointer type and bool.NULL (a macro that expands to 0 or (void*)0) in C++; use nullptr exclusively.nullptrint main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}