清华大学出版社 TSINGHUA UNIVERSITY PRESS 第十一章 结袍体与类用体
第十一章
清华大学出版社 TSINGHUA UNIVERSITY PRESS ●本章要点 结构体的定义\引用和初始化(1--5) 链表的概念和操作\建立\输出(6-7)
⚫ 本章要点 ◼结构体的定义\引用和初始化(1--5) ◼链表的概念和操作\建立\输出(6-7)
清华大学出版社 TSINGHUA UNIVERSITY PRESS §11.1概述 有时要将具有内在联系的多个不同类型的 数据组合成一个整体以便于引用。如 学生”stu1”的学号/姓名/性别/年龄/地址等 int num; char name[20]; char sex int age; int char addr30 若能用 stul num, student1age访问 Num name sex age score addr 100101Li Fun M 18 87.5 Beijing 图11-1
§11.1 概述 ◼ 有时要将具有内在联系的多个不同类型的 数据组合成一个整体以便于引用。如: 学生”stu1”的学号/姓名/性别/年龄/地址等 int num; char name[20]; char sex; int age; int char addr[30]; 若能用stu1.num,student1.age…访问 图11-1 100101 Li Fun M 18 87.5 Beijing Num name sex age score addr
清华大学世版 struct student TSINGHUA UNIVERSITY PRESS 结构体类型 成员类型 int num; char name 20: char sex 结构体 变量 nt age; float score; CIdri[30 };/不能丢此处表类型定〉结构体 struct student stu 1 成员 结构体包含结构体类型与结构体变量两层含义, 前者只声明结构体在内存中的存储结构;后者是结构体 类型的具体实例,编译系统只有定义了结构体变量后才 为会根据结构体类型为结构体变量分配内存空间
struct student { int num; char name[20]; char sex; int age; float score; char addr[30]; };/*分号不能丢,此处表类型定义完毕*/ struct student stu_1 结构体类型 成员类型 结构体 成员 结构体包含结构体类型与结构体变量两层含义, 前者只声明结构体在内存中的存储结构;后者是结构体 类型的具体实例,编译系统只有定义了结构体变量后才 为会根据结构体类型为结构体变量分配内存空间 结构体 变量
§11.2结构体类型与结构体变量的定义 (1)先定义结构体类型,后定义结构体变量 struct student{…} struct student student 1. student2 (2)定义结构体类型的同时定义结构体变量 struct date int year; int month; int day )date l, date2 (3)直接定义结构体类型变量 struct i int num; char name 201; char sex float score struct date birthday;/成员也可以是结构体类型*/ 3 student, student2;
§11.2 结构体类型与结构体变量的定义 (1)先定义结构体类型,后定义结构体变量 struct student {…}; struct student student1, student2; (2)定义结构体类型的同时定义结构体变量 struct date { int year; int month; int day; }date1,date2; (3) 直接定义结构体类型变量 struct { int num; char name[20]; char sex; float score; struct date birthday;/*成员也可以是结构体类型*/ }student1,student2;