复杂数据类型

上传人:nbwa****ajie 文档编号:51714150 上传时间:2018-08-16 格式:PPT 页数:30 大小:668.50KB
返回 下载 相关 举报
复杂数据类型_第1页
第1页 / 共30页
复杂数据类型_第2页
第2页 / 共30页
复杂数据类型_第3页
第3页 / 共30页
复杂数据类型_第4页
第4页 / 共30页
复杂数据类型_第5页
第5页 / 共30页
点击查看更多>>
资源描述

《复杂数据类型》由会员分享,可在线阅读,更多相关《复杂数据类型(30页珍藏版)》请在金锄头文库上搜索。

1、C C数数 据据 类类 型型 指针类型指针类型空类型空类型voidvoid定义类型定义类型typedeftypedef构造类型构造类型枚举类型枚举类型enumenum数组数组结构体结构体structstruct共用体共用体unionunion基本类型基本类型字符类型字符类型charchar实型实型单精度型单精度型floatfloat双精度型双精度型doubledouble整整 型型短整型短整型shortshort长整型长整型longlong整型整型intint只能定义单一的只能定义单一的 数据类型,反映数据类型,反映 事物单一属性事物单一属性复杂数据类型 uu学习的意义学习的意义如定义学生成绩

2、:如定义学生成绩:float score;float score;能定义复杂的数能定义复杂的数 据类型,反映事据类型,反映事 物多个属性物多个属性如定义学生信息:如定义学生信息: structstruct STU STU char no9; char no9; / /学号学号char name12; char name12; / /姓名姓名char sex; char sex; / /性别性别float score; float score; / /成绩成绩 student; student; 复杂数据类型丰富了复杂数据类型丰富了C C语言对数据信息的处理能力。语言对数据信息的处理能力。 离开

3、了复杂数据类型,很多信息的描述是无法进行定义离开了复杂数据类型,很多信息的描述是无法进行定义 ,更无法进行处理的。,更无法进行处理的。 计算机中的信息表示更多是由复杂数据类型来定义的,计算机中的信息表示更多是由复杂数据类型来定义的, 象象数据结构数据结构课程中的链表、树、图等课程中的链表、树、图等 可以更好地理解数据库中的记录的含义,可以更好地理解数据库中的记录的含义, 为为C+C+语言中类的概念的理解提供了帮助。语言中类的概念的理解提供了帮助。 1 1、结构体类型的定义、结构体类型的定义structstruct 结构体类型名结构体类型名 数据类型名数据类型名1 1 成员名成员名1 1;数据类

4、型名数据类型名2 2 成员名成员名2 2; 数据类型名数据类型名n n 成员名成员名n n; ;structstruct是是关键字关键字, , 不能省略不能省略合法标识符合法标识符 可省可省: :无名结构体无名结构体成员类型可以是成员类型可以是 基本型或构造型基本型或构造型以分号以分号; ;结尾结尾 例例1 1: structstruct Student_InfoStudent_Info char no9; char no9; / /学号学号char name20; char name20; / /姓名姓名char sex; char sex; / /性别性别unsigned unsigned

5、 intint age; age; / /年龄年龄unsigned unsigned intint classnoclassno; ; / /班级班级float grade; float grade; / /成绩成绩; ;例例2 2: structstruct Date Date intint year; year; / /年年intint month; month; / /月月intint day; day; / /日日; ;在结构体中数据类型相同的成员,既可逐个、逐行分别在结构体中数据类型相同的成员,既可逐个、逐行分别 定义,也可合并成一行定义,就象一次定义多个变量一样。定义,也可合并成一

6、行定义,就象一次定义多个变量一样。 structstruct Student_InfoStudent_Info char no9; char no9; / /学号学号char name20; char name20; / /姓名姓名char sex; char sex; / /性别性别unsigned unsigned intint age; age; / /年龄年龄unsigned unsigned intint classnoclassno; ; / /班级班级float grade; float grade; / /成绩成绩; ;structstruct Student_InfoStud

7、ent_Info char no9, name20, sex; char no9, name20, sex;unsigned unsigned intint age, age, classnoclassno; ;float grade; float grade; ; ;structstruct Date Date intint year; year; / /年年intint month; month; / /月月intint day; day; / /日日; ;structstruct Date Date intint year, month, day; year, month, day; ;

8、注意:注意:结构类型只是用户自定义的一种数据类型,用结构类型只是用户自定义的一种数据类型,用 来定义描述结构的组织形式来定义描述结构的组织形式, ,不分配内存不分配内存,只有用它来定,只有用它来定 义某个变量时,才会为该变量分配结构类型所需要大小义某个变量时,才会为该变量分配结构类型所需要大小 的内存单元。的内存单元。structstruct Student_InfoStudent_Info char no9, name20, sex; char no9, name20, sex;unsigned unsigned intint age, age, classnoclassno; ;float

9、 grade; float grade; ; ;structstruct Student_InfoStudent_Info student; student;例:例:2 2、结构体变量的定义和引用、结构体变量的定义和引用structstruct 结构体类型名结构体类型名 数据类型名数据类型名1 1 成员名成员名1 1; 数据类型名数据类型名n n 成员名成员名n n; ; structstruct 结构体类型名结构体类型名 变量名列表;变量名列表; 结构体变量的定义结构体变量的定义l l 间接定义法:间接定义法:先定义结构类型,再定义结构变量先定义结构类型,再定义结构变量 9 9字节字节202

10、0字节字节1 1字节字节2 2字节字节2 2字节字节4 4字节字节nononamenamesexsexageageclassnoclassnogradegrade内存映像内存映像 (BC(BC下下) )structstruct student; student;structstruct Student_InfoStudent_Info student1, student2;student1, student2;一次定义多个结构体类型变量一次定义多个结构体类型变量 定义指向结构体类型的指针变量定义指向结构体类型的指针变量 structstruct Student_InfoStudent_Info

11、 * *pstupstu; ; 间接定义法中几种错误的结构体变量的定义方法间接定义法中几种错误的结构体变量的定义方法 没有结构体类型名没有结构体类型名 Student_InfoStudent_Info student; student; 缺省缺省structstruct关键字关键字 structstruct Point Point p; p; structstruct Point Point intint x, y; x, y; ; 结构类型结构类型PointPoint定义定义 在后在后 2 2、结构体变量的定义和引用、结构体变量的定义和引用structstruct 结构体类型名结构体类型名

12、数据类型名数据类型名1 1 成员名成员名1 1; 数据类型名数据类型名n n 成员名成员名n n; 变量名列表变量名列表; 结构体变量的定义结构体变量的定义 l l 直接定义法:直接定义法:定义结构体类型的同时定义结构体变量定义结构体类型的同时定义结构体变量 structstruct Student_InfoStudent_Info char no9; char no9; / /学号学号char name20; char name20; / /姓名姓名char sex; char sex; / /性别性别unsigned unsigned intint age; age; / /年龄年龄unsigned unsigned intint classnoclassno; ; / /班级班级float grade; float grade; / /成绩成绩 student1, student2student1, student2; ;structstruct char no9; char no9; / /学号学号char name20; char name20; / /姓名姓名char sex; char

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号