long long int is a 64-bit integer data type.
An long long int is a keyword that can be used, depending on the standard used:
- long long int in the C++98 standard
- long long int in the C++11 standard
long long int in the C++98 standard
long long int is not guaranteed to be 64-bit in the C++98 standard.
#include <iostream> #include <boost/static_assert.hpp> int main() { BOOST_STATIC_ASSERT(sizeof(int) == 4); BOOST_STATIC_ASSERT(sizeof(long long int) == 8); long long int x = 1; int y = 1; std::cout << "#: int - long long int\n"; for (int i = 1; i!=64; ++i) { x*=2; y*=2; std::cout << i << ": " << x << ',' << y << '\n'; } }
Screen output:
Starting /MyFolder/CppLongLongInt... #: int - long long int 1: 2,2 ... 30: 1073741824,1073741824 31: 2147483648,-2147483648 32: 4294967296,0 ... 62: 4611686018427387904,0 63: -9223372036854775808,0 /MyFolder/CppLongLongInt exited with code 0
long long int in the C++11 standard
long long int is guaranteed to be 64-bit in the C++11 standard.
#include <iostream> int main() { static_assert(sizeof(int) == 4, "int has 4 bytes"); static_assert(sizeof(long long int) == 8, "long long int has 8 bytes"); long long int x = 1; int y = 1; std::cout << "#: int - long long int\n"; for (int i = 1; i!=64; ++i) { x*=2; y*=2; std::cout << i << ": " << x << ',' << y << '\n'; } }
Screen output:
Starting /MyFolder/CppLongLongInt... #: int - long long int 1: 2,2 ... 30: 1073741824,1073741824 31: 2147483648,-2147483648 32: 4294967296,0 ... 62: 4611686018427387904,0 63: -9223372036854775808,0 /MyFolder/CppLongLongInt exited with code 0
Technical note: the code shown is compiled successfully using the G++ 4.4.5 compiler, which is supplied with the Qt Creator 2.0.0 IDE.