C各个类型的大小
2016-01-21 15:34
429 查看
1个字节(byte)是8bit.
我采用的是64位系统,64位指CPU寄存器的数据宽度是64位的。
short 和 int:short比int更节省空间,short占内存是Int的一半,当要考虑程序的空间性而且short足以存储所需数据的话就用short。
float 和 double:double精度高,有效数字16位,float精度7位。但double消耗内存是float的两倍,double的运算速度比float慢得 多,能用单精度时不要用双精度(以省内存,加快运算速度)
64位系统:
int型:4字节
char型:1字节
bool型:1字节
double型:8字节
float型:4字节
long型:8字节
short型:2字节
unsigned int型:4字节
unsigned long型:8字节
bool型:1字节
测试程序:
//============================================================================
// Name : 各类型大小.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
int main() {
cout<<"int型:"<<sizeof(int)<<"字节"<<endl;
cout<<"char型:"<<sizeof(char)<<"字节"<<endl;
cout<<"bool型:"<<sizeof(bool)<<"字节"<<endl;
cout<<"double型:"<<sizeof(double)<<"字节"<<endl;
cout<<"float型:"<<sizeof(float)<<"字节"<<endl;
cout<<"long型:"<<sizeof(long)<<"字节"<<endl;
cout<<"short型:"<<sizeof(short)<<"字节"<<endl;
cout<<"unsigned int型:"<<sizeof(unsigned int)<<"字节"<<endl;
cout<<"unsigned long型:"<<sizeof(unsigned long)<<"字节"<<endl;
cout<<"bool型:"<<sizeof(bool)<<"字节"<<endl;
return 0;
}
我采用的是64位系统,64位指CPU寄存器的数据宽度是64位的。
short 和 int:short比int更节省空间,short占内存是Int的一半,当要考虑程序的空间性而且short足以存储所需数据的话就用short。
float 和 double:double精度高,有效数字16位,float精度7位。但double消耗内存是float的两倍,double的运算速度比float慢得 多,能用单精度时不要用双精度(以省内存,加快运算速度)
64位系统:
int型:4字节
char型:1字节
bool型:1字节
double型:8字节
float型:4字节
long型:8字节
short型:2字节
unsigned int型:4字节
unsigned long型:8字节
bool型:1字节
测试程序:
//============================================================================
// Name : 各类型大小.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
int main() {
cout<<"int型:"<<sizeof(int)<<"字节"<<endl;
cout<<"char型:"<<sizeof(char)<<"字节"<<endl;
cout<<"bool型:"<<sizeof(bool)<<"字节"<<endl;
cout<<"double型:"<<sizeof(double)<<"字节"<<endl;
cout<<"float型:"<<sizeof(float)<<"字节"<<endl;
cout<<"long型:"<<sizeof(long)<<"字节"<<endl;
cout<<"short型:"<<sizeof(short)<<"字节"<<endl;
cout<<"unsigned int型:"<<sizeof(unsigned int)<<"字节"<<endl;
cout<<"unsigned long型:"<<sizeof(unsigned long)<<"字节"<<endl;
cout<<"bool型:"<<sizeof(bool)<<"字节"<<endl;
return 0;
}
相关文章推荐
- c#设计模式-单例模式(面试题)
- extjs combobox 如何获取点击事件
- ORA-01565: error in identifying file '+DATA/ORACLE/spfileORACLE.ora'
- leetcode之happy number
- 剖析C++编程中friend关键字所修饰的友元函数和友元类
- Android中使用【microlog4】进行日志存储
- Mybatis学习笔记(3)之高级功能
- 发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容
- java 并发插入数据到oracle
- Recursion--递归
- 第一篇 前言
- 如何设置memcached来共享php的session
- Change color of GRUB
- Azure blob Storage Snapshot
- HDU 1051
- SQL Server 查询结果多行数据拼接
- Java继承和多态===Java多态和动态绑定
- 初识Face++在android上的应用
- diesel generator sale for Greece
- iOS-设置navibar背景图片