Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
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):
longis 32 bits (same size asint). - LP64 Data Model (64-bit Linux/macOS):
longis 64 bits. - ILP32 Data Model (32-bit systems):
longis 32 bits.
Syntax and Aliases
Thelong keyword can be used alone or combined with int and signedness modifiers. By default, long is signed.
Literals
To explicitly type an integer literal aslong, 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 oflong 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).
Master C++ with Deep Grasping Methodology!Learn More





