int float double 最大值,最小值

本文详细解析了C++中int、long、long long、float和double类型的存储范围,通过代码展示了各自的最大值和最小值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
  1. /*
  2.     coder: ACboy
  3. date: 2010-3-1
  4. */ 
  5. #include <iostream> 
  6. #include <float.h> 
  7. using namespace std; 
  8.  
  9. int main() 
  10.     cout << "int 类型能存储的最大值和最小值" << endl; 
  11.     cout << "INT_MAX = " << INT_MAX << endl; 
  12.     cout << "INT_MIN = " << INT_MIN << endl; 
  13.     cout << "long 类型能存储的最大值和最小值" << endl; 
  14.     cout << "LONG_MAX = " << LONG_MAX << endl;
  15.     cout << "LONG_MIN = " << LONG_MIN << endl; 
  16.     cout << "long long 类型能存储的最大值和最小值" << endl; 
  17.     cout << "LONG_LONG_MAX = " << LONG_LONG_MAX << endl; 
  18.     cout << "LONG_LONG_MIN = " << LONG_LONG_MIN << endl; 
  19.     cout << "float 类型能存储的最大值和最小值" << endl; 
  20.     cout << "FLT_MAX = " << FLT_MAX << endl; 
  21.     cout << "FLT_MIN = " << FLT_MIN << endl; 
  22.     cout << "double 类型能存储的最大值和最小值" << endl; 
  23.     cout << "DBL_MAX = " << DBL_MAX << endl; 
  24.     cout << "DBL_MIN = " << DBL_MIN << endl; 
  25.     return 0; 

从运行结果看:

int和long都是用32位来存储最大值和最小值分别为2147483647(109), -2147483648;

long long 是用64位来存储最大值和最小值分别为9223372036854775807(1018),-9223372036854775808;

float的最大值和最小值分别为3.40282e+038(1038),1.17549e-038(10-38);

double的最大值和最小值分别为1.79769e+308(10308),2.22507e-308(10-308)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值