不同操作系统和编译系统的数据类型大小不同
各种数据类型的大小由操作系统和编译系统决定
输出您电脑上各种数据类型的大小的代码(C++):
1 #include<iostream> 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_limits<signed char>::max)(); 16 cout << "\t\t最小值:" << (numeric_limits<signed char>::min)() << endl; 17 cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char); 18 cout << "\t最大值:" << (numeric_limits<unsigned char>::max)(); 19 cout << "\t\t最小值:" << (numeric_limits<unsigned char>::min)() << endl; 20 cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t); 21 cout << "\t最大值:" << (numeric_limits<wchar_t>::max)(); 22 cout << "\t\t最小值:" << (numeric_limits<wchar_t>::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<unsigned>::max)(); 31 cout << "\t最小值:" << (numeric_limits<unsigned>::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_limits<unsigned long>::max)(); 37 cout << "\t最小值:" << (numeric_limits<unsigned long>::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<size_t>::max)(); 49 cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl; 50 cout << "string: \t" << "所占字节数:" << sizeof(string) << endl; 51 // << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl; 52 cout << "type: \t\t" << "************size**************" << endl; 53 return 0; 54 }
引用:https://www.runoob.com/cplusplus/cpp-data-types.html
本文来自博客园,作者:꧁执笔小白꧂,转载请注明原文链接:https://www.cnblogs.com/qq2806933146xiaobai/p/12322863.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?