`long` — C++ Keyword

`long` — C++ Keyword

The long keyword in C++: a signed integer type at least 32 bits wide.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

long

Shorthand for long int. At least 32 bits on all platforms; 64 bits on Unix/Linux 64-bit systems but 32 bits on Windows 64-bit.

Syntax

long n;
long int n;
long long n;       // at least 64 bits (C++11 / C99)
unsigned long ul;
unsigned long long ull;

Example

#include <print>
#include <climits>

int main() {
    long a = 1'000'000L;
    long long b = 9'000'000'000LL;

    std::println("{}", a);   // 1000000
    std::println("{}", b);   // 9000000000

    std::println("long max: {}", LONG_MAX);
    std::println("long long max: {}", LLONG_MAX);
}

Notes

Example in practice

int 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;
}