C++中各种类型int double long的表示范围

来源:互联网 发布:视频旋转软件中文版 编辑:程序博客网 时间:2024/05/22 05:26
#include<iostream>#include <limits>using namespace std;int main(){cout << "类型 \t\t" << "含义\t\t" << "字节" <<endl;cout << "int \t\t" << "整型\t\t" << sizeof(int);cout << "\t最大值:" << (numeric_limits<int>::max)();    cout << "\t\t最小值:" << (numeric_limits<int>::min)() << endl; cout << "float \t\t" << "单精度浮点型 \t" <<sizeof(float);cout << "\t最大值:" << (numeric_limits<float>::max)();    cout << "\t\t最小值:" << (numeric_limits<float>::min)() << endl;  cout << "double \t\t" << "双精度浮点型 \t" << sizeof(double);cout << "\t最大值:" << (numeric_limits<double>::max)();    cout << "\t\t最小值:" << (numeric_limits<double>::min)() << endl;  cout << "long \t\t" << "长整型 \t\t" << sizeof(long);cout << "\t最大值:" << (numeric_limits<long>::max)();    cout << "\t\t最小值:" << (numeric_limits<long>::min)() << endl;   cout << "long long \t" << "长整型 \t\t" << sizeof(long long);cout << "\t最大值:" << (numeric_limits<long long>::max)();    cout << "\t最小值:" << (numeric_limits<long long>::min)() << endl;  cout << "long double \t"<< "拓展精度浮点数 \t" <<sizeof(long double);cout << "\t最大值:" << (numeric_limits<long double>::max)();    cout << "\t\t最小值:" << (numeric_limits<long double>::min)() << endl; cout << "short \t\t" << "短整型 \t\t" << sizeof(short);cout << "\t最大值:" << (numeric_limits<short>::max)();    cout << "\t\t\t最小值:" << (numeric_limits<short>::min)() << endl; cout << "bool \t\t" << "布尔类型 \t" << sizeof(bool)<<endl;cout << "char \t\t" << "字符 \t\t" << sizeof(char)<<endl;cout << "string \t\t" << "字符串 \t\t" << sizeof(string)<<endl;return 0; }
上面程序的结果为


我是用64位机win10下DevC++编译运行的,每次去查这个范围都不一样,好像是跟编译器,编译环境有关,所以写清楚这个。



0 0