原文链接 
  1. #include<iostream>
  2. #include<string>
  3. #include <limits>
  4. using namespace std;
  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. }

/*运行结果分析:

以上结果已经很明白了,一下补充说明几点:

概念、整型:表示整数、字符和布尔值的算术类型合称为整型(integral type)。

关于带符号与无符号类型:整型 int、stort  和  long 都默认为带符号型。要获得无符号型则必须制定该类型为unsigned,比如unsigned long。unsigned int类型可以简写为unsigned,也就是说,unsigned后不加其他类型说明符就意味着是unsigned int。

一字节表示八位,即:1byte = 8 bit;

int: 4byte =  32 bit 有符号signed范围:2^31-1 ~ -2^31即:2147483647 ~ -2147483648无符号unsigned范围:2^32-1 ~ 0即:4294967295 ~ 0

long: 4 byte = 32 bit 同int型

double: 8 byte = 64 bit 范围:1.79769e+308 ~ 2.22507e-308

long double: 12 byte = 96 bit 范围: 1.18973e+4932 ~ 3.3621e-4932

float: 4 byte = 32 bit 范围: 3.40282e+038 ~ 1.17549e-038

int、unsigned、long、unsigned long 、double的数量级最大都只能表示为10亿,即它们表示十进制的位数不超过10个,即可以保存所有9位整数。而short只是能表示5位;

另外对于浮点说而言:使用double类型基本上不会有错。在float类型中隐式的精度损失是不能忽视的,二双精度计算的代价相对于单精度可以忽略。事实上,在有些机器上,double类型比float类型的计算要快得多。float型只能保证6位有效数字,而double型至少可以保证15位有效数字(小数点后的数位),long double型提供的精度通常没有必要,而且还要承担额外的运行代价。

double是8字节共64位,其中小数位占52位,2-^52=2.2204460492503130808472633361816e-16,量级为10^-16,故能够保证2^-15的所有精度。

在有些机器上,用long类型进行计算所付出的运行时代价远远高于用int类型进行同样计算的代价,所以算则类型前要先了解程序的细节并且比较long类型与int类型的实际运行时性能代价。

转载于:https://www.cnblogs.com/liangliangdetianxia/p/4169778.html

C/C++中各种类型int、long、double、char表示范围(最大最小值)相关推荐

  1. c语言算式中有double和int,C语言当中int,float,double,char这四个有什么区别?

    区别在以下方面: 一.定义方面: 1.int为整数型,用于定义整数类型的数据 . 2.float为单精度浮点型,能准确到小数点后六位 . 3.double为双精度浮点型,能准确到小数点都十二位 . 4 ...

  2. Qt中 QString 和int,double等的转换

    Qt中 int ,float ,double转换为QString 有两种方法 1.使用 QString::number(); 如: long a = 63; QString s = QString:: ...

  3. C/C++语言中计算int,float,double,char四种数据类型所能表示的数据范围

    char        1字节    short       2字节    int         4字节    long        4字节    long long   8字节    float ...

  4. java中String与int/float/double/byte/数组

    原文链接:小宁博客[添加链接描述](https://www.sunxiaoning.com/language/634.html) int转换为String(int i=100) 第一种方法:s=i+& ...

  5. int float double char 所占字节数及数字范围之间的关系

    原码就是取 绝对值.反码是原码取反.补码是反码+1. int int 在32/64位系统中占4个字节,一个字节能含八位二进制数字0/1,四个字节含32位,所以表示的数的范围为-(2的31次方-1)到( ...

  6. C语言当中int,float,double,char这四个有什么区别?

    区别在以下方面: 一.定义方面: 1.int为整数型,用于定义整数类型的数据 . 2.float为单精度浮点型,能准确到小数点后六位 . 3.double为双精度浮点型,能准确到小数点都十二位 . 4 ...

  7. [C]C语言基本语句(5/7)→ 用scanf语句输入int, float, double, char型数据

    当需要用键盘输入一个或几个数字或字符,就要用到scanf 例1: 基本格式 #include<stdio.h> int main() {int a,b;scanf("%d,%d& ...

  8. C/C++ 各类型int、long、double、char、long long取值范围(基本类型的最大最小值)

    做题的时候经常会使用到数据类型的最大最小值(如int, long, long long, char等),我也查了很多次,这次就记下来当笔记吧. 参考了C++ prime plus.各个博客.教程和c+ ...

  9. java long类型大小_java中long类型占多少字节

    所谓的占用字节数 就是申请内存的时候所占的空间大小. long 8字节 最小值是 -9,223,372,036,854,775,808(-2^63): 最大值是 9,223,372,036,854,7 ...

最新文章

  1. ubuntu搭建svn、git遇到的问题及解决办法
  2. java servlet 3_java – Servlet 2.5和3之间有什么区别?
  3. poj3009深度优先搜索挑战程序设计竞赛
  4. Altium AD20大电流表层开窗,用特殊粘贴复制平面区域到其他层,阻焊开窗显示沉金LOGO
  5. python自动化客户端_python 在 nwjs 应用客户端做 UI 自动化
  6. tcpip详解有必要看吗_车辆有必要安装“行车记录仪”吗?如何挑选看这里!
  7. 网络信息安全风险评估
  8. 电磁场仿真——绘制电场线和等势线
  9. RBF神经网络滑模控制
  10. Java中浮点数转大写金额工具类
  11. 想要买房的人究竟有多可悲?! --水木周平
  12. openCV实践项目:银行卡卡号识别
  13. mysql handlers_MySQL handler相关状态参数解释
  14. 微信小程序的生命周期函数
  15. 【cocos2d-x入门实战】微信飞机大战之十四:背景音乐和音效
  16. Odoo与浪潮合资研发PS Cloud之如何在Odoo中进行搜索引擎优化(5)
  17. Xcode 下载加速及安装指南
  18. 大数据学习——HDFS退役旧数据节点
  19. EFR32 zigbee SDK协议栈EmberZnet 使用和下载
  20. CTF-安全杂项-功夫秘籍

热门文章

  1. css,js缓存,不能立即响应
  2. 保洁阿姨看完都会了!java导出excel并下载详解
  3. java怎么快速创建构造方法,详解系列文章
  4. Android性能优化之启动优化实战篇,最终入职阿里
  5. python【数据结构与算法】Floyd算法模拟
  6. 全卷积神经网路【U-net项目实战】Unet++
  7. c语言课程设计走迷宫游戏,C语言课程设计-迷宫游戏.doc
  8. 上海网络推广浅析外链对网站优化的影响有多大?需要注意什么?
  9. github 慢_告别github 下载慢问题,让你的github下载速度起飞
  10. js字符串怎么转python对象_js 对象转换为字符串