Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between long long and long int

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

like image 914
Syedsma Avatar asked Aug 11 '11 13:08

Syedsma


People also ask

Is long long int and long long same?

long and long int are identical. So are long long and long long int . In both cases, the int is optional. As to the difference between the two sets, the C++ standard mandates minimum ranges for each, and that long long is at least as wide as long .

What is the difference between long long long long int in C?

The long long takes twice as much memory as long. In different systems, the allocated memory space differs. On Linux environment the long takes 64-bit (8-bytes) of space, and the long long takes 128-bits (16-bytes) of space. This is used when we want to deal with some large value of integers.

What is the difference between int and long long int?

Generally, you can store larger numbers in a “long int” than you can in an “int”. On most (but not all) C++ implementations, an “int” is 32 bits long and can store any number between zero and about 4 billion. But a “long int” is (typically) 64 bits and can store numbers up to 16 quadrillion.

What are the differences between int long long long and short?

The minimum size for char is 8 bits, the minimum size for short and int is 16 bits, for long it is 32 bits and long long must contain at least 64 bits.


2 Answers

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.

like image 156
André Caron Avatar answered Oct 16 '22 04:10

André Caron


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.

like image 21
Arun Avatar answered Oct 16 '22 04:10

Arun