文档介绍:第2章数据类型与表达式
C++的数据类型
1、
2、
程序
数据结构
算法
数据结构
数据
数据类型
3、数据
常量, 变量
4、数据类型
整型,实型
例:数据结构——整型常量、实型变量
数据类型 基本类型 整型短整型(short int)
整型(int)
长整型(long int)
字符型(char)
浮点型 单精度型(float)
双精度型(double)
长双精度型(long double)
布尔型(bool)
空类型(void)
非基本类型 枚举类型(enum)
(构造类型) 数组类型 type []
结构体类型(struct)
共用体类型(union)
类类型(class)
指针类型 type *
引用类型 type &
布尔型就是逻辑型,空类型就是无值型。
int 4B 范围
unsigned int 4B
short 2B
unsigned short 2B
long 4B
unsigned long 4B
char 1B
unsigned char 1B
float 4B
double 8B
Long double 8B
说明:1)2)3)4)5)
常量
常量
常量(字面常量或直接常量)
-----其值不能改变的量称为常量。
例:1)整型常量: 12 ,0 ,-3
2)实型常量:-,
3)字符常量: 'a' ,'d' ,'A'
(注意:一定用单引号, 单个字符)
数值型常量
数值常量
1)整型常量的类型
整型常量的数值范围整型常量可看作的类型可赋给整型变量的类型
-32768 ~+32767 short short 或int 或long
-214783648~214783647 int int 或 long
0~65535(正数) unsigned short unsigned short
或unsigned int
或unsigned long
0~4294967295 unsigned int unsigned long
(正数)
或unsigned int
2)整型常量的表示方式
十进制整数: 123, -456
三种方式八进制整数: 以数字0开头的数,
0123
十六进制整数: 以数字0x开头的数,
0x123
整型常量后加一个字母l或L,则认为是 long 型
2. 实型常量(浮点数)
(1)实型常量的表示方式
1)十进制形式如:, .123, , 123. ,
2)指数形式如: 123e-3, 123E3
注意: ① e或 E 之前必须有数字;
② e或 E 之后必须为整数。
例:不合法
e3 .e3 e
2)实型常量的类型
一般双精度 double (8B)
例:
,
可强制定义为float (4B)
可在数后加f或F
如: F, 目的:提高运算速度。
也可强制定义为long double (8B)
可在数后加l或L
如: 或 L
有效位数