c++中各种数据类型所占字节
求各种数据类型所占用的字节数可调用sizeof函数,求各种数据类型的最大值可以调用limits标准库中的numeric_limits<T>::max(),numeric_limits<T>::min()函数
#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;
system("pause");
return 0;
}
c++中各种数据类型所占字节的更多相关文章
- c和java中各种数据类型所占字节
c java char 1 2 short 2 int 4 long 4 8 float 4 double 8
- 10055 - Hashmat the Brave Warrior & 各数据类型所占字节数 (C语言)
Problem A Hashmat the brave warrior Input: standard input Output: standard output Hashmat is a brave ...
- java基本数据类型所占字节数
JAVA基本数据类型所占字节数是多少?(32位系统) byte 1字节 short 2字节 int 4字节 ...
- 在C语言中基本数据类型所占的字节数
基本数据类型所占的字节数其实跟C语言本身没有太大的关系,它取决于编译器的位数,下面这张表说明了不同编译器下基本数据类型的长度: 32位编译器中各基本类型所占字节数: 注:对于32位的编译器,指针变量的 ...
- 转:C/C++基本数据类型所占字节数
参考:http://blog.csdn.net/vast_sea/article/details/8076934 关于这个基本的问题,很早以前就很清楚了,C标准中并没有具体给出规定那个基本类型应该是多 ...
- C/C++基本数据类型所占字节数
关于这个主要的问题,非常早曾经就非常清楚了,C标准中并没有详细给出规定那个基本类型应该是多少字节数,并且这个也与机器.OS.编译器有关,比方相同是在32bits的操作系统系,VC++的编译器下int类 ...
- C、C++数据类型所占字节数
C标准中并没有详细给出规定那个基本类型应该是多少字节数.详细与机器.OS.编译器有关,比方相同是在32bits的操作系统系,VC++的编译器下int类型为占4个字节:而tuborC下则是2个字节. 所 ...
- JAVA中求解对象所占字节大小
该类为cache4j缓存框架中的工具类方法,该方法实现了两个接口 接口1:计算对象在内存中所占字节数 接口2:复制对象,实现深度克隆效果,实现原理为先序列化对象,然后在反序列化对象:返回一个新的对象, ...
- JAVA基本数据类型所占字节数是多少?
byte 1字节 short 2字节 int 4字节 long 8字节 ...
随机推荐
- json的js和C#操作
C#端的WebService接口接收json格式数据,处理后以json格式返回result using System; using System.Collections.Generic; using ...
- Autofac创建实例的方法总结 【转】
Autofac创建实例的方法总结 1.InstancePerDependency 对每一个依赖或每一次调用创建一个新的唯一的实例.这也是默认的创建实例的方式. 官方文档解释:Configure t ...
- Oracle 回忆录
简述 工作时间说短也不算短了,掐指一算差不多三年了吧.以前都没有写过Blog,仅偶尔对所学和所用到的做些许整理,后面竟然没有把那留下来,悲催啊!留不下来的整理不是好东西(*^__^*) 嘻嘻……,现在 ...
- Gengxin讲STL系列——Queue和Stack
第三篇. 感觉队列和栈是必须的……所以决定加上这两个…… 我发现我已经买域名买上隐了……今天又买了个.top……真是智障…… Queue(队列FIFO)和Statk(栈LIFO). 那么为什么要这两个 ...
- PK投票效果
/** *createTime:2015-07-21 *updateTime:2015-06-22 *author:刘俊 *Description:PK投票 *phone:13469119119 ** ...
- Zend Studio 文件头和方法注释设置
在zend studio中选择窗口->首选项->PHP–>编辑器 –>模板 –>新建 然后添加 funinfo或fileinfo 模板代码根据下边定义的COPY过去就可以 ...
- python安装第三方包的两种方式
最近研究QQ空间.微博的(爬虫)模拟登录,发现都涉及RSA算法.于是需要下一个RSA包(第三方包).折腾了很久,主要是感觉网上很多文章对具体要在哪里操作写得不清楚.这里做个总结,以免自己哪天又忘了. ...
- 傻瓜式硬盘重装win7系统图文加视频教程
标准适用环境: win7系统还能用,但是想重装win7系统.[当然win7进不去也可以在PE进行] 其它 需要工具: win7 ISO镜像 | [ w ...
- mysql的client和sever之间通信password的传输方式
本文想要说明的是,当我们用mysql -uroot -p1234567 -h127.0.0.1 -P3306 去连接mysql server时密码是通过什么样的形式传过去的呢? 首先密码这种东西明文传 ...
- Android应用开发中Intent的作用及使用方法
Intent是一种运行时绑定(run-time binding)机制,它能在程序运行过程中连接两个不同的组件.通过Intent,你的程序可以向Android表达某种请求或者意愿,Android会根据意 ...