Skip to content
Tutorials Center
My learning

Topics

C Reference ยท Types and Literals

C long long: 64-bit integers

Reference for the C long long and unsigned long long types: guaranteed 64-bit range, LL and ULL literal suffixes, %lld and %llu, and overflow behavior.

long long is an integer type that is guaranteed to hold at least 64 bits. It was added in C99 so that portable programs could count past four billion without depending on what long happens to be. On every mainstream platform, long long is exactly 64 bits: values from about -9.2 ร— 10^18 to 9.2 ร— 10^18 when signed, and up to about 1.8 ร— 10^19 when unsigned.

Use it for file sizes, timestamps in milliseconds, factorials, large sums and any computation where int overflows. For exact-width needs, prefer int64_t.

C
long long total = 9000000000LL;
unsigned long long mask = 0xFFFFFFFFFFFFFFFFULL;

Try it

C Going past 32 bits

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

C The classic literal mistake

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Syntax

C
long long a;
long long int b;        /* same type */
signed long long c;
unsigned long long d;
Item Description
Minimum range -9223372036854775807 to 9223372036854775807 (signed); 0 to 18446744073709551615 (unsigned)
Limits LLONG_MIN, LLONG_MAX, ULLONG_MAX in <limits.h>; C23 adds LLONG_WIDTH and ULLONG_WIDTH
Literal suffix LL or ll (signed), ULL or ull (unsigned); the two L letters must have the same case (lL is invalid)
printf %lld, %llu, %llx
scanf %lld, %llu

Errors / undefined behavior: signed overflow is undefined, so LLONG_MAX + 1 is not safe. Unsigned arithmetic wraps modulo 2^64. Using %ld with a long long argument is undefined behavior on platforms where the sizes differ.

Usage notes

  • Literal types matter. 3000000000 has type long (or long long) automatically because it does not fit in int; but 1 << 40 with int operands overflows, so write 1LL << 40.
  • Widen before you multiply. (long long)a * b is a 64-bit product; (long long)(a * b) multiplies in int first and may overflow.
  • long vs long long: long is 32 bits on 64-bit Windows and 64 bits on Linux. long long is 64 bits everywhere.
  • Speed: on 64-bit CPUs there is no penalty; on 32-bit targets arithmetic is a few instructions slower.
  • Mixed arithmetic: an int combined with a long long is converted to long long; a signed long long combined with unsigned long long becomes unsigned, which may surprise you with negative values.
  • Format macros: for int64_t, use PRId64 from <inttypes.h> rather than assuming %lld.
  • Division and shifts: shifting by 64 or more is undefined. LLONG_MIN / -1 overflows.
  • Added in C99, and supported by every compiler in current use, including MSVC.