I know the difference between long and int But What is the difference between "long long" and "long int"
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 .
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With