c++ primer plus(一)数据类型

来源:互联网 发布:让客服刷新网络端口 编辑:程序博客网 时间:2024/04/29 19:05

1. 整数

1字节 == 8bit

8bit 可以表示0~255或-128-127  


short ,int , long

short == short int

long == long int

 

c++的标准:

short 至少16bit

int 至少与short一样长

long 至少与int一样长

 

float 不比double长,double 不比long double长

通常:sizeof(float) = 4

sizeof(double) = 8

sizeof(long double) = 10-16

 

思考题:

sizeof(short) = 2

short nMax = 32767

则nMax + 1 = ?

unsigned short nMin = 0

nMin - 1 = ?

 

2. 无符号unsigned

signed char    有符号

unsigned char  无符号

char 可以有符号,也可以无符号

 

可以有

unsigned short

unsigned long

unsigned int  // unsigned == unsigned int

 

3.  wchar_t宽字符类型

在支持两字节wchar_t的系统中,每个字符存储在2个字节的内存单元中。

L表示

wchar_t bob = L'P';

wcout << L"tall";

  

4. 数据类型转换

将一个较大的整型转化为较小的整数时,可能超出最大范围,通常只复制右边的字节。

static_cast:

static_cast<long>)(thorn);  

0 0