不同操作系统和编译系统的数据类型大小不同

各种数据类型的大小由操作系统和编译系统决定

输出您电脑上各种数据类型的大小的代码(C++):

 1 #include  
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     cout << "type: \t\t" << "************size**************" << endl;
 8     cout << "bool: \t\t" << "所占字节数:" << sizeof(bool);
 9     cout << "\t最大值:" << (numeric_limits<bool>::max)();
10     cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl;
11     cout << "char: \t\t" << "所占字节数:" << sizeof(char);
12     cout << "\t最大值:" << (numeric_limits<char>::max)();
13     cout << "\t\t最小值:" << (numeric_limits<char>::min)() << endl;
14     cout << "signed char: \t" << "所占字节数:" << sizeof(signed char);
15     cout << "\t最大值:" << (numeric_limitschar>::max)();
16     cout << "\t\t最小值:" << (numeric_limitschar>::min)() << endl;
17     cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char);
18     cout << "\t最大值:" << (numeric_limitschar>::max)();
19     cout << "\t\t最小值:" << (numeric_limitschar>::min)() << endl;
20     cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t);
21     cout << "\t最大值:" << (numeric_limits::max)();
22     cout << "\t\t最小值:" << (numeric_limits::min)() << endl;
23     cout << "short: \t\t" << "所占字节数:" << sizeof(short);
24     cout << "\t最大值:" << (numeric_limits<short>::max)();
25     cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl;
26     cout << "int: \t\t" << "所占字节数:" << sizeof(int);
27     cout << "\t最大值:" << (numeric_limits<int>::max)();
28     cout << "\t最小值:" << (numeric_limits<int>::min)() << endl;
29     cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned);
30     cout << "\t最大值:" << (numeric_limits::max)();
31     cout << "\t最小值:" << (numeric_limits::min)() << endl;
32     cout << "long: \t\t" << "所占字节数:" << sizeof(long);
33     cout << "\t最大值:" << (numeric_limits<long>::max)();
34     cout << "\t最小值:" << (numeric_limits<long>::min)() << endl;
35     cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long);
36     cout << "\t最大值:" << (numeric_limitslong>::max)();
37     cout << "\t最小值:" << (numeric_limitslong>::min)() << endl;
38     cout << "double: \t" << "所占字节数:" << sizeof(double);
39     cout << "\t最大值:" << (numeric_limits<double>::max)();
40     cout << "\t最小值:" << (numeric_limits<double>::min)() << endl;
41     cout << "long double: \t" << "所占字节数:" << sizeof(long double);
42     cout << "\t最大值:" << (numeric_limits<long double>::max)();
43     cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl;
44     cout << "float: \t\t" << "所占字节数:" << sizeof(float);
45     cout << "\t最大值:" << (numeric_limits<float>::max)();
46     cout << "\t最小值:" << (numeric_limits<float>::min)() << endl;
47     cout << "size_t: \t" << "所占字节数:" << sizeof(size_t);
48     cout << "\t最大值:" << (numeric_limits::max)();
49     cout << "\t最小值:" << (numeric_limits::min)() << endl;
50     cout << "string: \t" << "所占字节数:" << sizeof(string) << endl;
51     // << "\t最大值:" << (numeric_limits::max)() << "\t最小值:" << (numeric_limits::min)() << endl;  
52     cout << "type: \t\t" << "************size**************" << endl;
53     return 0;
54 }

引用:https://www.runoob.com/cplusplus/cpp-data-types.html

 

你可能感兴趣的:(不同操作系统和编译系统的数据类型大小不同)