#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类型的实际执行时性能代价。

评论欢迎。为了帮助我提高,欣赏!

!!

——桑海整理

C/C++各种类型int、long、double、char表示范围(最大和最小)的更多相关文章

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

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

  2. sizeof对int long double char的使用

    主要针对int long char double 字节长度的识记. 1 #include <stdio.h> 2 3 int main() 4 { 5 int a[100]; 6 int ...

  3. 基于layui,Jquery 表格动态编辑 设置 编辑值为 int 或者 double 类型及默认值

    首先先推荐大家在看这篇笔记时,阅读过我写的这篇 Layui表格编辑[不依赖Layui的动态table加载] 阅读过上面那篇笔记之后呢,才能更好的理解我现在所要说的这个东西 接下来废话不多说,上代码. ...

  4. C/C++中各种类型int、long、double、char表示范围(最大最小值)(转)

    #include<iostream> #include<string> #include <limits> using namespace std; int mai ...

  5. C++中将string类型转换为int, float, double类型 主要通过以下几种方式:

      C++中将string类型转换为int, float, double类型 主要通过以下几种方式: # 方法一: 使用stringstream stringstream在int或float类型转换为 ...

  6. QT中QString 与 int float double 等类型的相互转换

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

  7. C 语言实例 - 计算 int, float, double 和 char 字节大小

    C 语言实例 - 计算 int, float, double 和 char 字节大小 C 语言实例 C 语言实例 使用 sizeof 操作符计算int, float, double 和 char四种变 ...

  8. 如何判断当前修改过的datatable的某一列值是否为int型或double类型

    如何判断当前修改过的datatable的某一列值是否为int型或double类型 今天在做datatable数据验证时碰到要对datatable的列数据进行数据类型校验,因此记录一下本人校验的方法,如 ...

  9. int类型和char类型的区别

    下面三个定义式的区别: int i = 1; char i = 1; char i = '1'; int用来定义整型变量,char用来定义字符型变量,要清楚的知道三个定义式的区别,可以比较它们在内存中 ...

随机推荐

  1. 2014在百度之星资格赛的第二个问题Disk Schedule

    事实上,我认为它可以用来费用流问题.但光建地图上加班. ..不科学啊.. . 因副作用太大,否则,必然在.最后,想啊想,或者使用dp对.... 别想了一维dp... .我不知道我是怎么想.无论如何,这 ...

  2. 做一个自动修改本机IP和mac的bat文件

    原文:做一个自动修改本机IP和mac的bat文件 1.ip bat修改理论探讨 前两天我突然萌生了一个念头:能不能做一个小程序来实现自动配置或修改IP和mac,达到一键搞定的目的,这样尤其适合那些带着 ...

  3. 从jdbc到mybatis

    前面我已经写了几篇文章介绍mybatis的使用方法, 现准备从原理上分析mybatis, 本篇将会解说JDBC演变到mybatis的过程. JDBC查询 使用jdbc查询数据库一般有下面七个步骤: 1 ...

  4. Cookie概念

    ASP.NET Cookie概念.CURD操作.原理.实际运用   会话就WEB开发来说,一个会话就是你通过浏览器与服务器之间的一次通话,只不过这种通话是以用浏览器浏览的方式来实现的. 就会话的应用来 ...

  5. TCP与UDP的侵略性

    HTTP必须执行在TCP上吗?SSL必须执行在TCP上吗?...实际上HTTP并没有规定一定要执行在TCP上,甚至FTP也不一定要执行在TCP上!HTTP或者FTP仅仅是说底层信道要保证数据的按序传输 ...

  6. HDFS Safemode问题

    处于safemode的集群是无法接收不论什么写操作的,包含创建文件夹.删除文件.改动文件.上传文件等等. 关于safemode,在http://www.iteblog.com/archives/977 ...

  7. Spring-MVC4 + JPA2 + MySql-5.5 + SLF4J + JBoss WildFly-8.1开发环境的搭建

    面试被问Spring4,它的目的是把过去Spring3所有升级项目Spring4.现在将记录在此环境搭建过程. 第一次使用Maven Archetype创建一个项目框架,运行以下命令: mvn arc ...

  8. Objective-C路成魔【2-Objective-C 规划】

    郝萌主倾心贡献,尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额任意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 编译执行O ...

  9. POJ2195 Going Home 【最小费用流】+【最佳匹配图二部】

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18169   Accepted: 9268 Descr ...

  10. Android 应用程序窗口显示状态操作(requestWindowFeature()的应用)

     我们在开发程序是常常会须要软件全屏显示.自己定义标题(使用button等控件)和其它的需求,今天这一讲就是怎样控制Android应用程序的窗口显示. 首先介绍一个重要方法那就是requestWi ...