Skip to main content
long is a fundamental, signed integral data type in C++ guaranteed by the standard to be at least 32 bits in width. It is designed to represent whole numbers, though its exact memory footprint is compiler- and architecture-dependent based on the underlying data model.

Memory Size and Data Models

Unlike fixed-width integer types (e.g., int32_t, int64_t), the size of long varies across platforms:
  • Standard Guarantee: >= 32 bits.
  • LLP64 Data Model (64-bit Windows): long is 32 bits (same size as int).
  • LP64 Data Model (64-bit Linux/macOS): long is 64 bits.
  • ILP32 Data Model (32-bit systems): long is 32 bits.

Syntax and Aliases

The long keyword can be used alone or combined with int and signedness modifiers. By default, long is signed.

Literals

To explicitly type an integer literal as long, append the L or l suffix. For unsigned long, use UL, Ul, uL, or ul. Uppercase is standard practice to avoid visual confusion between the lowercase letter l and the number 1.

Value Ranges

The minimum and maximum representable values depend on the platform’s bit width. These boundaries can be queried programmatically using the <limits> header.

Type Conversion

In expressions involving mixed integral types, C++ applies the usual arithmetic conversions based on integer conversion rank. The C++ standard dictates that the rank of long is strictly greater than the rank of int, regardless of their actual bit widths on the target architecture. Consequently, if a binary operation involves an int and a long, the int operand always undergoes an implicit integral conversion to long before the expression is evaluated. In strict C++ terminology, this is an integral conversion, not an integral promotion (which applies exclusively to converting types smaller than int, such as short or char, up to int).
Tired of Poor C++ Skills? Fix That With Deep Grasping!Learn More