1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include <iostream>
int main() { std::cout << "---标准类型大小---" << std::endl; std::cout << "short size: " << sizeof(short) << std::endl; std::cout << "int size: " << sizeof(int) << std::endl; std::cout << "unsigned int size: " << sizeof(unsigned int) << std::endl; std::cout << "long size: " << sizeof(long) << std::endl; std::cout << "unsigned long size: " << sizeof(unsigned long) << std::endl; std::cout << "long long size: " << sizeof(long long) << std::endl; std::cout << "unsigned long long size: " << sizeof(unsigned long long) << std::endl; std::cout << "size_t size: " << sizeof(size_t) << std::endl; std::cout << "double size: " << sizeof(double) << std::endl; std::cout << "float size: " << sizeof(float) << std::endl; std::cout << "char size: " << sizeof(char) << std::endl; std::cout << "unsigned char size: " << sizeof(unsigned char) << std::endl; std::cout << "signed char size: " << sizeof(signed char) << std::endl; std::cout << "pointer size: " << sizeof(void*) << std::endl;
std::cout << std::endl; std::cout << "---自定义类型大小---" << std::endl; std::cout << "SHORT(short) size: " << sizeof(short) << std::endl; std::cout << "INT(int) size: " << sizeof(int) << std::endl; std::cout << "LONG(long) size: " << sizeof(long) << std::endl; std::cout << "UINT8(unsigned char) size: " << sizeof(unsigned char) << std::endl; std::cout << "UINT16(unsigned short) size: " << sizeof(unsigned short) << std::endl; std::cout << "UINT32(unsigned int) size: " << sizeof(unsigned int) << std::endl; std::cout << "UINT64(unsigned long long) size: " << sizeof(unsigned long long) << std::endl; std::cout << "INT8(char) size: " << sizeof(char) << std::endl; std::cout << "INT16(short) size: " << sizeof(short) << std::endl; std::cout << "INT32(int) size: " << sizeof(int) << std::endl; std::cout << "INT64(long long) size: " << sizeof(long long) << std::endl; std::cout << "FLOAT(float) size: " << sizeof(float) << std::endl; std::cout << "DOUBLE(double) size: " << sizeof(double) << std::endl; std::cout << "CHAR(char) size: " << sizeof(char) << std::endl; std::cout << "BOOL(int) size: " << sizeof(int) << std::endl; std::cout << "BYTE(unsigned char) size: " << sizeof(unsigned char) << std::endl; std::cout << "HANDLE(void*) size: " << sizeof(void*) << std::endl;
return 0; }
|