Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between long long and long

What's the difference between long long and long? And they both don't work with 12 digit numbers (600851475143), am I forgetting something?

#include <iostream> using namespace std;  int main(){   long long a = 600851475143; } 
like image 538
Hikari Iwasaki Avatar asked Jun 24 '11 01:06

Hikari Iwasaki


People also ask

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. The type int should be the integer type that the target processor is most efficiently working with. This allows great flexibility: for example, all types can be 64-bit.

Is long long int and long long same?

But before starting the blog post, I want to make you clear that long and long int are identical and also long long and long long int. In both cases, the int is optional. There are several shorthands for built-in types. Let's see some examples of signed built-in types.

What is mean by long long?

Long-long definitionA kind of integer variable , allowing a greater range of possible values than a long . noun. 1.

Why do we use long 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.


2 Answers

Going by the standard, all that's guaranteed is:

  • int must be at least 16 bits
  • long must be at least 32 bits
  • long long must be at least 64 bits

On major 32-bit platforms:

  • int is 32 bits
  • long is 32 bits as well
  • long long is 64 bits

On major 64-bit platforms:

  • int is 32 bits
  • long is either 32 or 64 bits
  • long long is 64 bits as well

If you need a specific integer size for a particular application, rather than trusting the compiler to pick the size you want, #include <stdint.h> (or <cstdint>) so you can use these types:

  • int8_t and uint8_t
  • int16_t and uint16_t
  • int32_t and uint32_t
  • int64_t and uint64_t

You may also be interested in #include <stddef.h> (or <cstddef>):

  • size_t
  • ptrdiff_t
like image 147
Joey Adams Avatar answered Oct 08 '22 08:10

Joey Adams


long long does not exist in C++98/C++03, but does exist in C99 and c++0x.

long is guaranteed at least 32 bits.

long long is guaranteed at least 64 bits.

like image 20
Cheers and hth. - Alf Avatar answered Oct 08 '22 10:10

Cheers and hth. - Alf