Skip to main content
The long keyword in C is a fundamental integer data type (implicitly long int) that guarantees a minimum storage size of 32 bits. It provides a larger or equal value range compared to the standard int type, depending on the compiler and the target architecture’s data model.

Memory Size and Data Models

The exact byte size of long is implementation-defined. While the C standard mandates a minimum of 32 bits, its actual size diverges across different 64-bit environments:
  • ILP32 (32-bit systems): 32 bits (4 bytes).
  • LLP64 (64-bit Windows): 32 bits (4 bytes).
  • LP64 (64-bit Unix/Linux/macOS): 64 bits (8 bytes).

Syntax and Modifiers

By default, long is signed, utilizing two’s complement representation. It can be explicitly modified using the unsigned keyword to shift the representable range to strictly non-negative values, effectively doubling the maximum positive limit.

Literal Suffixes

When parsing integer literals, the C compiler assigns the int type by default if the value fits. To explicitly force a literal to be evaluated as a long, append the L or l suffix (uppercase L is standard practice to avoid visual confusion with the digit 1). For unsigned variants, combine U and L.

Format Specifiers

When interfacing with standard I/O functions like printf and scanf, specific length modifiers (l) must be prepended to the integer conversion specifiers to prevent undefined behavior resulting from stack misalignment or truncation.
  • %ld or %li: Signed long
  • %lu: Unsigned long
  • %lx or %lX: Unsigned long in hexadecimal
  • %lo: Unsigned long in octal

Standard Limits

The absolute minimum and maximum representable values for the specific compilation target are exposed via macros in the <limits.h> standard library header.
Tired of Poor C Skills? Fix That With Deep Grasping!Learn More