What is the difference between long long and long int

22,412

Solution 1

There are several shorthands for built-in types.

  • short is (signed) short int
  • long is (signed) long int
  • long long is (signed) long long int.

On many systems, short is 16-bit, long is 32-bit and long long is 64-bit. However, keep in mind that the standard only requires

sizeof(char) == 1
sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)

And a consequence of this is that on an exotic system, sizeof(long long) == 1 is possible.

Solution 2

According to the C standard the integral types are defined to provide at least the following ranges:

int                     -32767 to               +32767 representable in 16 bits
long               -2147483647 to          +2147483647 representable in 32 bits
long long -9223372036854775807 to +9223372036854775807 representable in 64 bits

Each can be represented as to support a wider range. On common 32 bit systems int and long have the same 32 bit representation.

Note that negative bounds are symmetric to their positive counterparts to allow for sign and magnitude representations: the C language standard does not impose two's complement.

Solution 3

On 64 bit systems it doesn't make any difference in their sizes. On 32 bit systems long long is guaranteed store values of 64 bit range.

Just to avoid all these confusions, it is always better to use the standard integral types: (u)int16_t, (u)int32_t and (u)int64_t available via stdint.h which provides transparency.

Solution 4

long long may be a bigger type than long int. For example on x86 32 bit long long would be a 64-bit type rather than 32 bit for long int.

Solution 5

An int on 16 bit systems was 16 bits. A "long" was introduced as a 32 bit integer, but on 32 bit systems long and int mean the same thing (both are 32 bit.) So on 32 and 64 bit systems, long long and long int are both 64 bit. The exception is 64 bit UNIX where long is 64 bits.

See the integer Wikipedia article for a more detailed table.

Share:
22,412
Syedsma
Author by

Syedsma

Updated on July 14, 2022

Comments

  • Syedsma
    Syedsma almost 2 years

    I know the difference between long and int But What is the difference between "long long" and "long int"