On this page
  1. nullptr
  2. Overview
  3. Notes & Pitfalls
  4. Example

nullptr

Prev: Lambdas | Up: builtins | Next: Structured Bindings
Rel: References & Rvalues, std::unique_ptr
Ref: cppreference — nullptr
Tags: #public #prog #cpp #builtins #tier/core


Overview

nullptr (C++11) is the type-safe null pointer literal of type std::nullptr_t. It implicitly converts to any pointer or pointer-to-member type, but never to int—eliminating overload ambiguity caused by C's NULL macro (0 or 0L).

Notes & Pitfalls

Example

#include <cassert>

int pick(int)  { return 1; }
int pick(int*) { return 2; }

int main() {
    int* p = nullptr;
    assert(p == nullptr && pick(nullptr) == 2);
}

Linked from

Related notes