long long
基本数据类型
目标编译器: x86_64-linux-gnu
-整数类型 | 等价类型 | 占用字节数 |
---|---|---|
short | short int | 2 bytes |
signed short | ||
signed short int | ||
unsigned short | unsigned short int | 2 bytes |
unsigned short int | ||
int | int | 4 bytes |
signed | ||
signed int | ||
unsigned | unsigned int | 4 bytes |
unsigned int | ||
long | long int | 8 bytes |
long int | ||
signed long | ||
signed long int | ||
unsigned long | unsigned long int | 8 bytes |
unsigned long int | ||
long long | long long int | 8 bytes |
long long int | ||
signed long long | ||
signed long long int | ||
unsigned long long | unsigned long long int | 8 bytes |
unsigned long long int |
- 可以观察到在我的编译器上, long 与long long 都是占用8个字节
long long 取值范围
头文件中与long long相关3个宏
- LLONG_MIN
- LLONG_MAX
- ULLONG_MAX(无符号超长整型最小值为0)
#include <iostream>
#include <climits>
int main() {
long long longlongTest1 = 1;
long long int longlongTest2 = 2;
signed long long int longlongTest3 = 3;
std::cout << sizeof(longlongTest1) << sizeof(longlongTest2) << sizeof(longlongTest3) << std::endl;
std::cout << "long long min" << LLONG_MIN << " " << std::hex << LLONG_MIN << std::endl;
std::cout << "long long max" << LLONG_MAX << " " << std::hex << LLONG_MAX << std::endl;
std::cout << "unsigned long long max" << ULLONG_MAX << " " << std::hex << ULLONG_MAX << std::endl;
}
输出结果:
long long min-9223372036854775808 8000000000000000
long long max7fffffffffffffff 7fffffffffffffff
unsigned long long maxffffffffffffffff ffffffffffffffff