C语言结构体和共用体
第九章;内容提要;结构体结构体是一种构造数据类型(自定义类型)。 结构体的使用分三步: (1)定义结构体类型 (2)定义结构体变量 (3)使用结构体变量;9.1结构体类型;结构体类型定义;结构体类型变量的定义;结构体类型变量的定义;结构体类型变量的定义;结构体变量的使用;结构体变量的使用;结构体变量的初始化;结构体变量的初始化;结构体变量的赋值;9.2 结构体数组;结构体数组的定义;结构体数组的初始化;结构体数组的初始化;9.3 结构体指针变量;指向结构体的指针;指向结构体数组的指针;结构体变量作函数参数;#include #include struct stu{ long num; char name[20]; char sex; float score;};void main(){ void print(struct stu); struct stu student1={11001,"Li ping",‘M’,45}; print(student1);}void print(struct stu student) //输出结构体student中各成员值{ printf("no=%ld,name=%s,sex=%c,score=%f\n",student.num, student.name, student.sex,student.score);};指向结构体变量的指针作函数参数;#include #include struct stu{ long num; char name[20]; char sex; float score;};void main(){ void print(struct stu *); struct stu student[5]={{11001,"Li ping",‘M’,45}, {11002,"Zhang ping",‘M’,62.5}, {11003,"He fang",‘F’,92.5},{11004,"Cheng ling",‘F’,87},{11005,"Wang ming",‘M’,58}}; struct stu *p1; printf("num name sex score \n"); for(p1=student; p1num, p->name, p->sex, p->score); };9.4 链表;9.4 链表;单向链表结构示意图;动态存储分配函数;动态存储分配函数;链表的操作;建立链表;建立链表;输出链表;插入一个结点;删除一个结点;9.5 共用体;共用体类型变量的定义;共用体变量的使用;9.6 枚举类型;枚举变量定义;枚举变量的使用;9.7 枚举类型;9.7 枚举类型;The end!