Traditionally, a literal is an expression denoting a constant whose type and value are evident from its spelling. For example, 42 is a literal, while x is not since one must see its declaration to know its type and read previous lines of code to know its value.

However, C++11 also added user-defined literals, which are not literals in the traditional sense but can be used as a shorthand for function calls.

true, false

A keyword denoting values of type bool.

bool ok = true;
if (!f()) {
    ok = false;
    goto end;
}

nullptr

Introduced in C++ 11.

A keyword denoting a null pointer constant. It can be converted to any pointer or pointer-to-member type, yielding a null pointer of the resulting type.

Widget* p = new Widget();
delete p;
p = nullptr; // set the pointer to null after deletion

Note that nullptr is not itself a pointer. The type of nullptr is a fundamental type known as std::nullptr_t.

void f(int* p);

template <class T>
void g(T* p);

void h(std::nullptr_t p);

int main() {
    f(nullptr); // ok
    g(nullptr); // error
    h(nullptr); // ok
}

Integer literal

An integer literal is a primary expression of the form

It is a non-zero decimal digit (1, 2, 3, 4, 5, 6, 7, 8, 9), followed by zero or more decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

int d = 42;

It is the digit zero (0) followed by zero or more octal digits (0, 1, 2, 3, 4, 5, 6, 7)

int o = 052