《第9章 结构体》由会员分享,可在线阅读,更多相关《第9章 结构体(28页珍藏版)》请在金锄头文库上搜索。
1、第第9章章 结构体结构体26 八月八月 2024提出问题提出问题v在我们定义变量的时候,有时一些不同类型的变量需要组合成一在我们定义变量的时候,有时一些不同类型的变量需要组合成一个整体,便于引用个整体,便于引用v例如:我们要处理一个学生的信息,包括:例如:我们要处理一个学生的信息,包括: 学号、姓名、性别、年龄、成绩、地址学号、姓名、性别、年龄、成绩、地址学号、姓名、性别、年龄、成绩、地址学号、姓名、性别、年龄、成绩、地址按照以往定义变量的方式,我们可以这样定义:按照以往定义变量的方式,我们可以这样定义:intint num; num;char name20;char name20;char
2、sex;char sex;intint age; age;float score;float score;char addr50;char addr50;这些变量相互独立,这些变量相互独立,很难反映出它们的内在联系很难反映出它们的内在联系structstruct student student ;结构体结构体26 八月八月 2024声明结构体类型声明结构体类型v结构体是一种结构体是一种构造数据类型构造数据类型构造数据类型构造数据类型 其目的是:其目的是:把不同类型的数据组成一个整体把不同类型的数据组成一个整体把不同类型的数据组成一个整体把不同类型的数据组成一个整体属于属于用户自定义用户自定义用
3、户自定义用户自定义的数据类型的数据类型structstruct 结构体名结构体名结构体名结构体名 类型标识符类型标识符类型标识符类型标识符 成员名;成员名;成员名;成员名; 类型标识符类型标识符类型标识符类型标识符 成员名;成员名;成员名;成员名; ;structstruct 是关键字是关键字不能省略不能省略合法标识符,可省略合法标识符,可省略省略时无结构体名省略时无结构体名成员类型可以是基本数据类型成员类型可以是基本数据类型或构造数据类型型或构造数据类型型需要说明的是:需要说明的是: 定义结构体,定义结构体,不是定义变量不是定义变量不是定义变量不是定义变量, 而是而是定义一种数据类型定义一种
4、数据类型定义一种数据类型定义一种数据类型 所定义的结构体类型与系统所定义的结构体类型与系统 提供的标准数据类型(提供的标准数据类型(int 、 float、double、char等)等) 具有同样的作用和地位,都具有同样的作用和地位,都 可以可以用来声明变量的类型用来声明变量的类型用来声明变量的类型用来声明变量的类型 不同的是:结构体类型需要不同的是:结构体类型需要 用户自己指定用户自己指定26 八月八月 2024声明结构体类型声明结构体类型例如:例如:structstruct student student intint num; num; char name20;char name20;
5、char sex;char sex; intint age; age; float score;float score; char addr30;char addr30;声明结构体类型,只是描述了该类型数据的声明结构体类型,只是描述了该类型数据的组织形式组织形式组织形式组织形式是对一种用户自定义的是对一种用户自定义的数据类型数据类型数据类型数据类型的描述,并不占内存空间的描述,并不占内存空间name name num num sex sex age age score score addraddr 4 4字节字节字节字节 4 4字节字节字节字节 20 20字节字节字节字节 1 1字节字节字节字
6、节 4 4字节字节字节字节 30 30字节字节字节字节studentstudent类型的变量,将按照这种结构在内存中分配空间类型的变量,将按照这种结构在内存中分配空间类型的变量,将按照这种结构在内存中分配空间类型的变量,将按照这种结构在内存中分配空间每个变量都占每个变量都占每个变量都占每个变量都占6363个字节个字节个字节个字节26 八月八月 2024声明结构体变量声明结构体变量v定义结构体类型的变量有三种方式定义结构体类型的变量有三种方式1.1.1.1.先定义结构体类型,再定义结构体变量先定义结构体类型,再定义结构体变量先定义结构体类型,再定义结构体变量先定义结构体类型,再定义结构体变量st
7、ructstruct 结构体名结构体名结构体名结构体名 类型标识符类型标识符类型标识符类型标识符 成员名;成员名;成员名;成员名; 类型标识符类型标识符类型标识符类型标识符 成员名;成员名;成员名;成员名; ;structstruct 结构体名结构体名结构体名结构体名 变量名表变量名表变量名表变量名表; ;structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; float score;float score; char addr30;char
8、 addr30; structstruct student student stu1, stu2; stu1, stu2; stu1.name stu1.name stu1.num stu1.num stu1.sex stu1.sex stu1.age stu1.age stu1.score stu1.score stu1.addr stu1.addr 4 4字节字节4 4字节字节 20 20字节字节 1 1字节字节 4 4字节字节 30 30字节字节stu2.name stu2.name stu2.num stu2.num stu2.sex stu2.sex stu2.age stu2.ag
9、e stu2.score stu2.score stu2.addr stu2.addr 4 4字节字节 4 4字节字节 20 20字节字节 1 1字节字节 4 4字节字节 30 30字节字节stu1stu1和和和和stu2stu2各占各占各占各占6363个字节个字节个字节个字节26 八月八月 2024声明结构体变量声明结构体变量v定义结构体类型的变量有三种方式定义结构体类型的变量有三种方式2.2.2.2.定义结构体类型的同时定义结构体变量定义结构体类型的同时定义结构体变量定义结构体类型的同时定义结构体变量定义结构体类型的同时定义结构体变量structstruct 结构体名结构体名结构体名结构体
10、名 类型标识符类型标识符类型标识符类型标识符 成员名;成员名;成员名;成员名; 类型标识符类型标识符类型标识符类型标识符 成员名;成员名;成员名;成员名; 变量名表变量名表变量名表变量名表; ;structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; float score;float score; char addr30;char addr30; stu1, stu2; stu1, stu2; 26 八月八月 2024声明结构体变量声明结构体
11、变量v定义结构体类型的变量有三种方式定义结构体类型的变量有三种方式3.3.3.3.直接定义结构体变量直接定义结构体变量直接定义结构体变量直接定义结构体变量structstruct 类型标识符类型标识符类型标识符类型标识符 成员名;成员名;成员名;成员名; 类型标识符类型标识符类型标识符类型标识符 成员名;成员名;成员名;成员名; 变量名表变量名表变量名表变量名表; ;structstruct intint num; num;char name20;char name20;char sex;char sex; intint age; age; float score;float score; c
12、har addr30;char addr30; stu1, stu2; stu1, stu2; 用用用用无名结构体无名结构体无名结构体无名结构体直接定义直接定义直接定义直接定义变量变量变量变量只能一次只能一次只能一次只能一次26 八月八月 2024声明结构体变量声明结构体变量v定义结构体类型的变量有三种方式的定义结构体类型的变量有三种方式的比较比较比较比较:第一种和第二种是等价的第一种和第二种是等价的第一种和第二种是等价的第一种和第二种是等价的structstruct student student intint num; num;char name20;char name20;char se
13、x;char sex; intint age; age; float score;float score; char addr30;char addr30; stu1, stu2; stu1, stu2; structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; float score;float score; char addr30;char addr30; structstruct student student stu1, stu2; s
14、tu1, stu2; 这两种方式定义的结构体数据类型,这两种方式定义的结构体数据类型,这两种方式定义的结构体数据类型,这两种方式定义的结构体数据类型,可以做多次声明可以做多次声明可以做多次声明可以做多次声明structstruct student student stu3, stu4; stu3, stu4;structstruct student student stu3, stu4; stu3, stu4;26 八月八月 2024声明结构体变量声明结构体变量vv第三种声明方式第三种声明方式第三种声明方式第三种声明方式只说明了要定义的结构体变量的组织形式只说明了要定义的结构体变量的组织形式只
15、说明了要定义的结构体变量的组织形式只说明了要定义的结构体变量的组织形式没有说明没有说明没有说明没有说明所定义的所定义的所定义的所定义的结构体类型名称结构体类型名称结构体类型名称结构体类型名称,不能再次做变量声明不能再次做变量声明不能再次做变量声明不能再次做变量声明structstruct intint num; num;char name20;char name20;char sex;char sex; intint age; age; float score;float score; char addr30;char addr30; stu1, stu2; stu1, stu2; struc
16、tstruct intint num; num;char name20;char name20;char sex;char sex; intint age; age; float score;float score; char addr30;char addr30; stu1, stu2; stu1, stu2;structstruct stu3, stu4; stu3, stu4; PP26 八月八月 2024声明结构体变量声明结构体变量vv结构体类型结构体类型结构体类型结构体类型与与结构体变量结构体变量结构体变量结构体变量概念不同概念不同 结构体类型结构体类型结构体类型结构体类型:不分配内
17、存,不能赋值、存取、运算:不分配内存,不能赋值、存取、运算 结构体变量结构体变量结构体变量结构体变量:分配内存,能够赋值、存取、运算:分配内存,能够赋值、存取、运算v结构体可嵌套结构体可嵌套structstruct date date intint month; month;intint day; day; intint year; year;structstruct student student intint num; num; char name20;char name20; structstruct date birthday; date birthday; stustu; ;numn
18、um name name birthdaybirthdaymonthmonthdaydayyearyearstructstruct student student intint num; num; char name20;char name20; structstruct date date intint month; month;intint day; day; intint year; year; birthday;birthday; stustu; ;26 八月八月 2024声明结构体变量声明结构体变量vv结构体成员名结构体成员名结构体成员名结构体成员名与程序中与程序中变量名变量名变量名
19、变量名可相同,不会混淆可相同,不会混淆#include #include void main()void main() structstruct student student intint numnum; ; char name20;char name20; stustu; ; intint numnum; ; num=0; num=0; stu.numstu.num=1;=1; 26 八月八月 2024引用结构体变量引用结构体变量引用结构体变量的规则引用结构体变量的规则引用结构体变量的规则引用结构体变量的规则vv结构体变量不能整体引用,只能引用变量成员结构体变量不能整体引用,只能引用变量成
20、员结构体变量不能整体引用,只能引用变量成员结构体变量不能整体引用,只能引用变量成员引用方式:引用方式: 结构体变量名结构体变量名结构体变量名结构体变量名. . . . 成员名成员名成员名成员名成员成员(分量分量)运算符运算符优先级:优先级:1结合性:从左向右结合性:从左向右structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; float score;float score; char addr30;char addr30; stu1, st
21、u2; stu1, stu2; 不能将结构体变量作为一个整体进不能将结构体变量作为一个整体进不能将结构体变量作为一个整体进不能将结构体变量作为一个整体进行输入或输出,但是可整体初始化行输入或输出,但是可整体初始化行输入或输出,但是可整体初始化行输入或输出,但是可整体初始化scanf(scanf(%d%d, %s, %c, %d, %f, %s, &stu1, %s, %c, %d, %f, %s, &stu1); );printf(printf(%d%d, %s, %c, %d, %f, %s, stu2, %s, %c, %d, %f, %s, stu2); );structstruct s
22、tudent student stu3=101, Jack, M, 19, 87.5, stu3=101, Jack, M, 19, 87.5, DaLianDaLian; PP#include #include void main()void main() structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; float score;float score; char addr30;char addr30; stu1, stu1, stu
23、2 = 101, Jack, M, 19, 87.5, stu2 = 101, Jack, M, 19, 87.5, DaLianDaLian; ; scanfscanf (%d, %s, %c, %d, %f, %s, &stu1); (%d, %s, %c, %d, %f, %s, &stu1);printfprintf (%d, %s, %c, %d, %f, %s, stu2) ; (%d, %s, %c, %d, %f, %s, stu2) ; scanfscanf (%d, %s, %c, %d, %f, %s, &stu1.num, stu1.name, (%d, %s, %c,
24、 %d, %f, %s, &stu1.num, stu1.name, &stu1.sex, &stu1.age, &stu1.score, stu1.addr); &stu1.sex, &stu1.age, &stu1.score, stu1.addr);printfprintf (%d, %s, %c, %d, %f, %s, stu2.num, stu2.name, (%d, %s, %c, %d, %f, %s, stu2.num, stu2.name, stu2.sex, stu2.age, stu2.score, stu2.addr) ; stu2.sex, stu2.age, st
25、u2.score, stu2.addr) ;26 八月八月 2024引用结构体变量引用结构体变量引用结构体变量的规则引用结构体变量的规则引用结构体变量的规则引用结构体变量的规则vv结构体变量的成员可以进行该成员类型允许的所有运算结构体变量的成员可以进行该成员类型允许的所有运算结构体变量的成员可以进行该成员类型允许的所有运算结构体变量的成员可以进行该成员类型允许的所有运算structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; float sco
26、re;float score; char addr30;char addr30; stu1, stu2 stu1, stu2 = 101, Jack, M, 19, 87.5, = 101, Jack, M, 19, 87.5, DaLianDaLian; ; stu1.num = 100;stu1.num = 100;stu1.score = stu2.score + 10;stu1.score = stu2.score + 10;stu2.age +;stu2.age +;strcpy(stu1.addr, stu2.addr);strcpy(stu1.addr, stu2.addr);2
27、6 八月八月 2024引用结构体变量引用结构体变量引用结构体变量的规则引用结构体变量的规则引用结构体变量的规则引用结构体变量的规则vv可以引用结构体变量的成员的地址,也可以引用结构体变量的地址可以引用结构体变量的成员的地址,也可以引用结构体变量的地址可以引用结构体变量的成员的地址,也可以引用结构体变量的地址可以引用结构体变量的成员的地址,也可以引用结构体变量的地址structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; float score;
28、float score; char addr30;char addr30; stu1, stu2 stu1, stu2 = 101, Jack, M, 19, 87.5, = 101, Jack, M, 19, 87.5, DaLianDaLian; ; scanf(%dscanf(%d, &stu1.num);, &stu1.num);printf(%xprintf(%x, &stu2.num);, &stu2.num);printf(%xprintf(%x, &stu2);, &stu2);26 八月八月 2024引用结构体变量引用结构体变量引用结构体变量的规则引用结构体变量的规则引用结构
29、体变量的规则引用结构体变量的规则vv可以将一个结构体的值赋值给另一个结构体可以将一个结构体的值赋值给另一个结构体可以将一个结构体的值赋值给另一个结构体可以将一个结构体的值赋值给另一个结构体#include #include void main()void main() structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; float score;float score; char addr30;char addr30; stu1, stu1
30、, stu2 = 101, Jack, M, 19, 87.5, stu2 = 101, Jack, M, 19, 87.5, DaLianDaLian; ;stu1=stu2;stu1=stu2;printfprintf (%d, %s, %c, %d, %f, %sn, stu2.num, stu2.name, (%d, %s, %c, %d, %f, %sn, stu2.num, stu2.name, stu2.sex, stu2.age, stu2.score, stu2.addr) ; stu2.sex, stu2.age, stu2.score, stu2.addr) ;print
31、fprintf (stu1: %x, %xn, &stu1, &stu1.num); (stu1: %x, %xn, &stu1, &stu1.num); printfprintf (stu2: %x, %xn, &stu2, &stu2.addr); (stu2: %x, %xn, &stu2, &stu2.addr); 101, Jack, M, 19, 87.500000, DaLianstu1: ff5e, ff5estu2: ff9a, ffb7ff9a+2926 八月八月 2024引用结构体变量引用结构体变量引用结构体变量的规则引用结构体变量的规则引用结构体变量的规则引用结构体变量
32、的规则vv当结构体的成员也是一个结构体类型时,需要使用当结构体的成员也是一个结构体类型时,需要使用当结构体的成员也是一个结构体类型时,需要使用当结构体的成员也是一个结构体类型时,需要使用多个成员运算多个成员运算多个成员运算多个成员运算符符符符,一级一级找到最低的一级成员,一级一级找到最低的一级成员,一级一级找到最低的一级成员,一级一级找到最低的一级成员,只能对最低级的成员进行赋值、存取及运算只能对最低级的成员进行赋值、存取及运算只能对最低级的成员进行赋值、存取及运算只能对最低级的成员进行赋值、存取及运算#include #include void main()void main() struc
33、tstruct date date intint month; month;intint day; day; intint year; year;structstruct student student intint num; num; char name20;char name20; structstruct date birthday date birthday; ; stustu=101, Jack, =101, Jack, 1, 31, 19861, 31, 1986 ; ;printfprintf (num: % (num: %dnnamednname: %: %snbirthday
34、snbirthday: %d-%d-%dn, : %d-%d-%dn, stu.numstu.num, , stu.namestu.name, , stu.birthday.yearstu.birthday.year, , stu.birthday.monthstu.birthday.month, , stu.birthday.daystu.birthday.day) ;) ; num: 101name: Jackbirthday: 1986-1-3126 八月八月 2024引用结构体变量引用结构体变量引用结构体变量的规则引用结构体变量的规则引用结构体变量的规则引用结构体变量的规则vv不能直接
35、判断两个同类型的结构体变量是否相等不能直接判断两个同类型的结构体变量是否相等不能直接判断两个同类型的结构体变量是否相等不能直接判断两个同类型的结构体变量是否相等必须判断其各成员必须判断其各成员必须判断其各成员必须判断其各成员#include #include void main()void main() structstruct student student intint num; num; char name20;char name20; stu1=101, Jack, stu2stu1=101, Jack, stu2; ;stu2 = stu1;stu2 = stu1;if (stu2=
36、stu1)if (stu2=stu1)printfprintf (stu2 = stu1) ; (stu2 = stu1) ;elseelseprintfprintf (stu2 stu1) ; (stu2 stu1) ; Error 9: Illegal structure operation in function main产生编译错误!产生编译错误!产生编译错误!产生编译错误!#include #include void main()void main() structstruct student student intint num; num; char name20;char nam
37、e20; stu1=101, Jack, stu2stu1=101, Jack, stu2; ;stu2 = stu1;stu2 = stu1; if (if (stu2.num=stu1.numstu2.num=stu1.num & & strcmp(stu2.name, stu1.name)=0strcmp(stu2.name, stu1.name)=0) )printfprintf (stu2 = stu1) ; (stu2 = stu1) ;elseelseprintfprintf (stu2 stu1) ; (stu2 stu1) ; stu2 = stu126 八月八月 2024结
38、构体数组结构体数组v我们一共学习三种数组:我们一共学习三种数组:一般数组、指针数组、结构体数组一般数组、指针数组、结构体数组v结构体数组是指:结构体数组是指:数组中的元素都是结构体类型的数据数组中的元素都是结构体类型的数据数组中的元素都是结构体类型的数据数组中的元素都是结构体类型的数据 它们分别包括各自的成员项它们分别包括各自的成员项它们分别包括各自的成员项它们分别包括各自的成员项v三种定义形式:三种定义形式:定义形式定义形式定义形式定义形式1 1:structstruct student student intint num; num;char name20;char name20;char
39、 sex;char sex; intint age; age; structstruct student student stu2; stu2; numnumnamenamesexsexageagenumnumnamenamesexsexageage stu0 stu0 stu1 stu12525B B 定义形式定义形式定义形式定义形式2 2:structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; stu2; stu2; 定义形式定义形式定义
40、形式定义形式3 3:structstruct intint num; num;char name20;char name20;char sex;char sex; intint age; age; stu2; stu2; 26 八月八月 2024结构体数组结构体数组v结构体数组的初始化结构体数组的初始化 顺序初始化顺序初始化顺序初始化顺序初始化structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; structstruct student s
41、tudent stu2 = 100, Jack , M , 20,stu2 = 100, Jack , M , 20, 100, Marry , F , 19; 100, Marry , F , 19; n n分行初始化分行初始化分行初始化分行初始化structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; structstruct student student stu2 = stu2 = 100, Jack , M , 20100, Jack
42、 , M , 20, , 100, Marry , F , 19100, Marry , F , 19 ; ; 在全部初始化的时候,可在全部初始化的时候,可在全部初始化的时候,可在全部初始化的时候,可以省略数组长度以省略数组长度以省略数组长度以省略数组长度structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; structstruct student student stustu = = 100, Jack , M , 20100, Jack
43、 , M , 20, , 100, Marry , F , 19100, Marry , F , 19 ; ; 26 八月八月 2024结构体数组结构体数组v结构体数组元素的应用结构体数组元素的应用结构体数组名结构体数组名结构体数组名结构体数组名 下标下标下标下标 . . . . 成员名成员名成员名成员名structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; structstruct student student stu2; stu2; s
44、tu0.num=100;stu0.num=100;strcpy(stu0.name, Jack);strcpy(stu0.name, Jack);stu1.age +;stu1.age +;26 八月八月 2024结构体数组结构体数组v统计候选人的选票统计候选人的选票:定义结构体类型,其成员为候选人姓名和该候选人票数定义结构体类型,其成员为候选人姓名和该候选人票数定义该结构体数组,包含定义该结构体数组,包含3 3个元素,分别为个元素,分别为3 3个候选人个候选人读入所有投票中的姓名,若名字与某候选人相符,则将该候读入所有投票中的姓名,若名字与某候选人相符,则将该候选人的票数成员分量加选人的票数
45、成员分量加1 1最终输出票数结果最终输出票数结果#include #include void main()void main() structstruct person person char name20;char name20;intint count; count; leader3 = Jack,0, Marry,0, Tom,0leader3 = Jack,0, Marry,0, Tom,0; ;intint i, j, n=10; i, j, n=10;char name20;char name20;for ( i=1; i=n; i+ )for ( i=1; i=n; i+ ) s
46、canf(%sscanf(%s, name);, name);for ( j=0; j3; j+)for ( j=0; j3; j+)if (if (strcmp(namestrcmp(name, leaderj.name)=0, leaderj.name)=0) ) leaderj.count+leaderj.count+; ; break;break; for ( j=0; j3; j+)for ( j=0; j-成员名成员名成员名成员名structstruct student student intint num; num;char name20;char name20;char sex
47、;char sex; intint age; age; stustu; ; structstruct student * p = & student * p = &stustu; ; stu.numstu.num=100;=100;(*p).num = 101;(*p).num = 101;p - num = 101;p - num = 101;注意:注意:. .的优先级比的优先级比* *的高的高* * p . num p . num * (* (p . num)p . num) 指向运算符指向运算符指向运算符指向运算符优先级优先级优先级优先级: 1: 1结合方向:从左向右结合方向:从左向右结
48、合方向:从左向右结合方向:从左向右#include #include void main()void main() structstruct student student intint num; num;char name 20;char name 20;char sex;char sex;float score;float score; stustu, * p = &, * p = &stustu; ;p -p - numnum=101;=101;strcpystrcpy( (*p).name(*p).name, Jack);, Jack);scanf(%cscanf(%c, , & p
49、-& p - sexsex); ); scanf(%fscanf(%f, , & & stu.scorestu.score); ); printf(Noprintf(No: %: %dnNamednName: %: %snSexsnSex: %: %cnScorecnScore: %.1fn, : %.1fn, (*p).num(*p).num, , p - namep - name, , p - sexp - sex, , stu.scorestu.score); ); M 78 No: 101Name: JackSex: MScore: 78.026 八月八月 2024指向结构体类型数据的
50、指针指向结构体类型数据的指针v使用结构体指针变量引用结构体成员使用结构体指针变量引用结构体成员结构体变量名结构体变量名结构体变量名结构体变量名. .成员名成员名成员名成员名 (*(*结构体指针名结构体指针名结构体指针名结构体指针名).).成员名成员名成员名成员名 结构体指针名结构体指针名结构体指针名结构体指针名-成员名成员名成员名成员名structstruct student student intint num; num;char name20;char name20;char sex;char sex; intint age; age; stustu; ; structstruct stu
51、dent * p = & student * p = &stustu; ; p - age =20;p - age =20;printf(Ageprintf(Age: %dn, : %dn, p - age +p - age +); );printf(Ageprintf(Age: %dn, : %dn, + p - age+ p - age); );Age: 20Age: 2226 八月八月 2024指向结构体类型数据的指针指向结构体类型数据的指针v指向结构体数组的指针指向结构体数组的指针#include #include void main()void main() structstruct
52、 student student intint num; num;char name 20;char name 20;char sex;char sex;float score;float score; stu3= 101, Jack, M, 78, 102, Marry, F, 95, stu3= 101, Jack, M, 78, 102, Marry, F, 95, 103, Tom, M, 62 ; 103, Tom, M, 62 ;structstruct student * p = student * p = stustu; ;printf(No.tNametsextscorenp
53、rintf(No.tNametsextscoren););for(; pstu+3; p+)for(; pp - numnum, , p -p - namename, , p -p - sexsex, , p -p - scorescore); ); 101101JackJackMM78.078.0102102MarryMarryF F95.095.0 stu0 stu0 stu1 stu1103103TomTomMM62.062.0 stu2 stu2p p No.Name sexscore101JackM78.00102Marry F95.00103TomM62.00p pp p26 八月
54、八月 2024第十章第十章 结构体结构体vv主要内容主要内容主要内容主要内容 结构体类型的声明结构体类型的声明结构体类型的声明结构体类型的声明 结构体变量的定义结构体变量的定义结构体变量的定义结构体变量的定义 结构体数组结构体数组结构体数组结构体数组 结构体指针的使用结构体指针的使用结构体指针的使用结构体指针的使用 vv要求掌握程序:要求掌握程序:要求掌握程序:要求掌握程序:例题例题例题例题26 八月八月 2024 课外作业:课外作业:课外作业:课外作业:P P 一、单选题一、单选题P P 二、填空题二、填空题 P P 三、读程序、写结果三、读程序、写结果 上机题目:上机题目:上机题目:上机题目:作业作业