c++ sizeof() 位运算
- sizeof() 函数是返回值的单位是 Byte,1 Byte = 8 bits.
- 目前,c++ 最长的数值类型可以有 64 位。
1 #include <iostream> 2 #include <climits> 3 4 int main() 5 { 6 unsigned long long int a = 1; /* 1 = 0000 0001 */ 7 unsigned long long int b = 0; 8 // unsigned long long int c = pow(2,64) - 1; 9 10 b = a << 63; /*4 = 0000 0000 */ 11 std::cout << "b = " << b << std::endl; 12 13 std::cout << "size of int = " << sizeof(int) << std::endl; 14 std::cout << "size of unsigned long long int = " << sizeof(unsigned long long int) << std::endl; 15 16 return 0; 17 }
out
1 b = 9223372036854775808 2 size of int = 4 3 size of unsigned long long int = 8