C/C++中各种类型int、long、double、char表示范围(最大最小值)
- #include<iostream>
- #include<string>
- #include <limits>
- using namespace std;
- int main()
- {
- cout << "type: \t\t" << "************size**************"<< endl;
- cout << "bool: \t\t" << "所占字节数:" << sizeof(bool);
- cout << "\t最大值:" << (numeric_limits<bool>::max)();
- cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl;
- cout << "char: \t\t" << "所占字节数:" << sizeof(char);
- cout << "\t最大值:" << (numeric_limits<char>::max)();
- cout << "\t\t最小值:" << (numeric_limits<char>::min)() << endl;
- cout << "signed char: \t" << "所占字节数:" << sizeof(signed char);
- cout << "\t最大值:" << (numeric_limits<signed char>::max)();
- cout << "\t\t最小值:" << (numeric_limits<signed char>::min)() << endl;
- cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char);
- cout << "\t最大值:" << (numeric_limits<unsigned char>::max)();
- cout << "\t\t最小值:" << (numeric_limits<unsigned char>::min)() << endl;
- cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t);
- cout << "\t最大值:" << (numeric_limits<wchar_t>::max)();
- cout << "\t\t最小值:" << (numeric_limits<wchar_t>::min)() << endl;
- cout << "short: \t\t" << "所占字节数:" << sizeof(short);
- cout << "\t最大值:" << (numeric_limits<short>::max)();
- cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl;
- cout << "int: \t\t" << "所占字节数:" << sizeof(int);
- cout << "\t最大值:" << (numeric_limits<int>::max)();
- cout << "\t最小值:" << (numeric_limits<int>::min)() << endl;
- cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned);
- cout << "\t最大值:" << (numeric_limits<unsigned>::max)();
- cout << "\t最小值:" << (numeric_limits<unsigned>::min)() << endl;
- cout << "long: \t\t" << "所占字节数:" << sizeof(long);
- cout << "\t最大值:" << (numeric_limits<long>::max)();
- cout << "\t最小值:" << (numeric_limits<long>::min)() << endl;
- cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long);
- cout << "\t最大值:" << (numeric_limits<unsigned long>::max)();
- cout << "\t最小值:" << (numeric_limits<unsigned long>::min)() << endl;
- cout << "double: \t" << "所占字节数:" << sizeof(double);
- cout << "\t最大值:" << (numeric_limits<double>::max)();
- cout << "\t最小值:" << (numeric_limits<double>::min)() << endl;
- cout << "long double: \t" << "所占字节数:" << sizeof(long double);
- cout << "\t最大值:" << (numeric_limits<long double>::max)();
- cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl;
- cout << "float: \t\t" << "所占字节数:" << sizeof(float);
- cout << "\t最大值:" << (numeric_limits<float>::max)();
- cout << "\t最小值:" << (numeric_limits<float>::min)() << endl;
- cout << "size_t: \t" << "所占字节数:" << sizeof(size_t);
- cout << "\t最大值:" << (numeric_limits<size_t>::max)();
- cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl;
- cout << "string: \t" << "所占字节数:" << sizeof(string) << endl;
- // << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl;
- cout << "type: \t\t" << "************size**************"<< endl;
- return 0;
- }
/*运行结果分析:
以上结果已经很明白了,一下补充说明几点:
概念、整型:表示整数、字符和布尔值的算术类型合称为整型(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表示范围(最大最小值)相关推荐
- c语言算式中有double和int,C语言当中int,float,double,char这四个有什么区别?
区别在以下方面: 一.定义方面: 1.int为整数型,用于定义整数类型的数据 . 2.float为单精度浮点型,能准确到小数点后六位 . 3.double为双精度浮点型,能准确到小数点都十二位 . 4 ...
- Qt中 QString 和int,double等的转换
Qt中 int ,float ,double转换为QString 有两种方法 1.使用 QString::number(); 如: long a = 63; QString s = QString:: ...
- C/C++语言中计算int,float,double,char四种数据类型所能表示的数据范围
char 1字节 short 2字节 int 4字节 long 4字节 long long 8字节 float ...
- java中String与int/float/double/byte/数组
原文链接:小宁博客[添加链接描述](https://www.sunxiaoning.com/language/634.html) int转换为String(int i=100) 第一种方法:s=i+& ...
- int float double char 所占字节数及数字范围之间的关系
原码就是取 绝对值.反码是原码取反.补码是反码+1. int int 在32/64位系统中占4个字节,一个字节能含八位二进制数字0/1,四个字节含32位,所以表示的数的范围为-(2的31次方-1)到( ...
- C语言当中int,float,double,char这四个有什么区别?
区别在以下方面: 一.定义方面: 1.int为整数型,用于定义整数类型的数据 . 2.float为单精度浮点型,能准确到小数点后六位 . 3.double为双精度浮点型,能准确到小数点都十二位 . 4 ...
- [C]C语言基本语句(5/7)→ 用scanf语句输入int, float, double, char型数据
当需要用键盘输入一个或几个数字或字符,就要用到scanf 例1: 基本格式 #include<stdio.h> int main() {int a,b;scanf("%d,%d& ...
- C/C++ 各类型int、long、double、char、long long取值范围(基本类型的最大最小值)
做题的时候经常会使用到数据类型的最大最小值(如int, long, long long, char等),我也查了很多次,这次就记下来当笔记吧. 参考了C++ prime plus.各个博客.教程和c+ ...
- java long类型大小_java中long类型占多少字节
所谓的占用字节数 就是申请内存的时候所占的空间大小. long 8字节 最小值是 -9,223,372,036,854,775,808(-2^63): 最大值是 9,223,372,036,854,7 ...
最新文章
- ubuntu搭建svn、git遇到的问题及解决办法
- java servlet 3_java – Servlet 2.5和3之间有什么区别?
- poj3009深度优先搜索挑战程序设计竞赛
- Altium AD20大电流表层开窗,用特殊粘贴复制平面区域到其他层,阻焊开窗显示沉金LOGO
- python自动化客户端_python 在 nwjs 应用客户端做 UI 自动化
- tcpip详解有必要看吗_车辆有必要安装“行车记录仪”吗?如何挑选看这里!
- 网络信息安全风险评估
- 电磁场仿真——绘制电场线和等势线
- RBF神经网络滑模控制
- Java中浮点数转大写金额工具类
- 想要买房的人究竟有多可悲?! --水木周平
- openCV实践项目:银行卡卡号识别
- mysql handlers_MySQL handler相关状态参数解释
- 微信小程序的生命周期函数
- 【cocos2d-x入门实战】微信飞机大战之十四:背景音乐和音效
- Odoo与浪潮合资研发PS Cloud之如何在Odoo中进行搜索引擎优化(5)
- Xcode 下载加速及安装指南
- 大数据学习——HDFS退役旧数据节点
- EFR32 zigbee SDK协议栈EmberZnet 使用和下载
- CTF-安全杂项-功夫秘籍
热门文章
- css,js缓存,不能立即响应
- 保洁阿姨看完都会了!java导出excel并下载详解
- java怎么快速创建构造方法,详解系列文章
- Android性能优化之启动优化实战篇,最终入职阿里
- python【数据结构与算法】Floyd算法模拟
- 全卷积神经网路【U-net项目实战】Unet++
- c语言课程设计走迷宫游戏,C语言课程设计-迷宫游戏.doc
- 上海网络推广浅析外链对网站优化的影响有多大?需要注意什么?
- github 慢_告别github 下载慢问题,让你的github下载速度起飞
- js字符串怎么转python对象_js 对象转换为字符串