关键字:C++, 数据类型, VS2015。

OS:Windows 10。

ANSI C/C++基本数据类型:

Type

Size

数值范围

无值型void

0 byte

无值域

布尔型bool

1 byte

true   false

有符号短整型short [int] /signed short [int]

2 byte

-32768~32767

无符号短整型unsigned short [int]

2 byte

0~65535

有符号整型int /signed [int]

4 byte

-2147483648~2147483647

无符号整型unsigned [int]

4 byte

0~4294967295

有符号长整型long [int]/signed long [int]

4 byte

-2147483648~2147483647

无符号长整型unsigned long [int]

4 byte

0~4294967295

long long

8 byte

0~18446744073709552000

有符号字符型char/signed char

1 byte

-128~127

无符号字符型unsigned char

1 byte

0~255

宽字符型wchar_t (unsigned short.)

2 byte

0~65535

单精度浮点型float

4 byte

-3.4E-38~3.4E+38

双精度浮点型double

8 byte

1.7E-308~1.7E+308

long double

8 byte

 

指针(char*)

4 byte/8byte

32bit的应用程序指针是4byte。

64bit的应用程序指针是8byte。

注:

(1)类型修饰符signed和unsigned用于修饰字符型和整形。

(2)类型修饰符short和long用于修饰字符型和整形。

(3)当用signed和unsigned、short和long修饰int整形时,int可省略。

(4)其中bool和wchar_t是C++特有的。对于条件判断,零为假,非零为真,对bool变量可赋非0非1的其他真值。

(5)float的精度(6位有效数字)通常是不够的,double类型可以保证10位有效数字,能够满足大多数计算的需要。使用double类型基本不会出错,在float类型中存在隐式的精度损失。默认的浮点字面值常量为double类型,在数值后面加上F或f表示单精度,例如3.14159F。浮点数float、double的存储设计,从本质上来说是设计了一个数值映射,充分利用了二进制存储的特点。参考IEEE754浮点数表示标准。

(6)指针在32bit应用程序里大小是4byte,在64bit应用程序里面大小是8byte。

-----------------------------------------------------------------------------------------------------------------

下面用VS2015创建一个Win32控制台工程来检验各数据类型的大小,代码如下:

#include "stdafx.h"
#include <iostream>
using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
cout << "sizeof(bool)" << sizeof(bool) << endl;
cout << "sizeof(short )" << sizeof(short) << endl;
cout << "sizeof(signed short)" << sizeof(signed short) << endl;
cout << "sizeof(unsigned short)" << sizeof(unsigned short) << endl;
cout << "sizeof(int)" << sizeof(int) << endl;
cout << "sizeof(unsigned int)" << sizeof(unsigned int) << endl;
cout << "sizeof(long)" << sizeof(long) << endl;
cout << "sizeof(unsigned long)" << sizeof(unsigned long) << endl;
cout << "sizeof(long long)" << sizeof(long long) << endl;
cout << "sizeof(char)" << sizeof(char) << endl;
cout << "sizeof(unsigned char)" << sizeof(unsigned char) << endl;
cout << "sizeof(wchar_t)" << sizeof(wchar_t) << endl;
cout << "sizeof(float)" << sizeof(float) << endl;
cout << "sizeof(double)" << sizeof(double) << endl;
cout << "sizeof(long double)" << sizeof(long double) << endl;
cout << "sizeof(char*)" << sizeof(char*) << endl; return ;
}
sizeof是C/C++中的一个操作符(operator),简单的说其作用就是返回一个对象或者类型所占的内存字节数。
MSDN上的解释为:
The sizeof keyword gives the amount of storage, in bytes, associated with a variable or a type(including aggregate types). This keyword returns a value of type size_t.
 
运行结果(32bit):

sizeof(bool)1
sizeof(short )2
sizeof(signed short)2
sizeof(unsigned short)2
sizeof(int)4
sizeof(unsigned int)4
sizeof(long)4
sizeof(unsigned long)4
sizeof(long long)8
sizeof(char)1
sizeof(unsigned char)1
sizeof(wchar_t)2
sizeof(float)4
sizeof(double)8
sizeof(long double)8
sizeof(char*)4

运行结果(64bit):

sizeof(bool)1
sizeof(short )2
sizeof(signed short)2
sizeof(unsigned short)2
sizeof(int)4
sizeof(unsigned int)4
sizeof(long)4
sizeof(unsigned long)4
sizeof(long long)8
sizeof(char)1
sizeof(unsigned char)1
sizeof(wchar_t)2
sizeof(float)4
sizeof(double)8
sizeof(long double)8
sizeof(char*)8

C++数据类型总结的更多相关文章

  1. JavaScript 中的数据类型

    Javascript中的数据类型有以下几种情况: 基本类型:string,number,boolean 特殊类型:undefined,null 引用类型:Object,Function,Date,Ar ...

  2. JS 判断数据类型的三种方法

    说到数据类型,我们先理一下JavaScript中常见的几种数据类型: 基本类型:string,number,boolean 特殊类型:undefined,null 引用类型:Object,Functi ...

  3. Python高手之路【二】python基本数据类型

    一:数字 int int(整型): 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位系统上,整数的位数为64位,取值 ...

  4. UniqueIdentifier 数据类型 和 GUID 生成函数

    UniqueIdentifier 数据类型用于存储GUID的值,占用16Byte. SQL Server将UniqueIdentifier存储为16字节的二进制数值,Binary(16),按照特定的格 ...

  5. SQL Server常见数据类型介绍

    数据表是由多个列组成,创建表时必须明确每个列的数据类型,以下列举SQL Server常见数据类型的使用规则,方便查阅. 1.整数类型 int 存储范围是-2,147,483,648到2,147,483 ...

  6. 由js apply与call方法想到的js数据类型(原始类型和引用类型)

    原文地址:由js apply与call方法想到的js数据类型(原始类型和引用类型) js的call方法与apply方法的区别在于第二个参数的不同,他们都有2个参数,第一个为对象(即需要用对象a继承b, ...

  7. python 数据类型 ----字典

    字典由一对key:value 组成的 python中常用且重量级的数据类型 1. key , keys, values 字典由一对key:value 组成的 python中常用且重量级的数据类型 1. ...

  8. SQL数据类型

    1.Character 字符串: 数据类型 描述 存储 char(n) 固定长度的字符串.最多8,000个字符. n varchar(n) 可变长度的字符串.最多8,000个字符.   varchar ...

  9. 跟着老男孩教育学Python开发【第二篇】:Python基本数据类型

    运算符 设定:a=10,b=20 . 算数运算 2.比较运算 3.赋值运算 4.逻辑运算 5.成员运算 基本数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**3 ...

  10. 我的MYSQL学习心得(二) 数据类型宽度

    我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...

随机推荐

  1. [iOS 10 day by day] Day 1:开发 iMessage 的第三方插件

    本文介绍了 iOS 10 的一个重要更新:Messages 应用支持第三方插件了.作者用一个小游戏作为例子,说明了插件开发从建工程开始,到绘制界面.收发消息的全过程. <iOS 10 day b ...

  2. argparse - 命令行选项与参数解析(转)

    argparse - 命令行选项与参数解析(译)Mar 30, 2013 原文:argparse – Command line option and argument parsing 译者:young ...

  3. C# WinForm 中ComboBox数据绑定的问题 (转)

    来自:http://blog.sina.com.cn/s/blog_5fb9e26301013wga.html C# WinForm 中ComboBox数据绑定的问题 怎样让WinForm中的Comb ...

  4. POWER DESIGN

    一.概念数据模型概述数据模型是现实世界中数据特征的抽象.数据模型应该满足三个方面的要求:1)能够比较真实地模拟现实世界2)容易为人所理解3)便于计算机实现 概念数据模型也称信息模型,它以实体-联系(E ...

  5. python 元类——metaclass

    from stack overflow:http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python Classes ...

  6. 【简单dp+模拟】hdu-5375(2015多校#7-1007)

    给你一个二进制数,,每一位有一个权值,让你转格雷码,求所对应格雷码位为1的权值的和:二进制位中的某些位为?,你需要给这些问号赋值使得到的和最大. 首先你得知道二进制转格雷码的规则,即格雷码位为[二进制 ...

  7. Spring 循环引用(singleton与prototype初始化的区别)

    原文链接请参见:http://blog.csdn.net/u010723709/article/details/47185959

  8. 【.net】创建属于自己的log组件——改进版

    在上一篇随笔中,建立了一个自己的Log简单日志记录类   可是在众多园友的提点下,对于线程,阻塞,资源竞争等都没有仔细的去了解 在这版的改进中,我们新加了线程操作,线程等待,以及多层的错误捕获.[不知 ...

  9. Jersey(1.19.1) - Sub-resources

    @Path may be used on classes and such classes are referred to as root resource classes. @Path may al ...

  10. SQL自动补充其他月份为0

    ,) ), Sales int,Dates datetime) insert into ProductSale ,'2014-01-05' UNION ALL ,'2014-02-05' UNION ...