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

#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++编译运行的,每次去查这个范围都不一样,好像是跟编译器,编译环境有关,所以写清楚这个。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值