81结构体类型与结构体变量 8.1.6指向结构体变量的指针 令其值是该结构体变量所分配的存储区域的首地址 令结构体指针变量的定义 struct student struct student *p=&stul; int num 10001 char name 20l; char sex Int age loat score, }stul={10001," zhang","M',19,8}; 通过指针访问结构体变量的成员 令结构体变量中简单成员的引用: 结构体变量名成员名 结构体指针→>成员名 (结构体指针)成员名 ☆☆第8章结构体、共用体与枚举类型 16
☆☆ 第8章 结构体、共用体与枚举类型 16 8.1 结构体类型与结构体变量 8.1.6 指向结构体变量的指针 ❖ 其值是该结构体变量所分配的存储区域的首地址 ❖ 结构体指针变量的定义 struct student struct student *p=&stu1; { int num; char name[20]; char sex; int age; float score; }stu1={10001,"zhang",'M',19,88}; P 88 19 M zhang 10001 ❖ 通过指针访问结构体变量的成员 ❖ 结构体变量中简单成员的引用: 结构体变量名.成员名 结构体指针->成员名 (*结构体指针).成员名
81结构体类型与结构体变量 例8-3使用指向结构体变量的指针访问输出结构体变量中各个 成员的值。 #include <stdio. h> include <string.h> void maino 令思考:如何输出班级n个学生的 i struct student 信息? int num: char name[20; char sex; int age float score }stul={10001," zhang","M',1988} struct student p=&stul so. printf("d, %S, %c, %d, %6.2f\n",p-num, p->name,p- x,p->age, p->score) ☆☆第8章结构体、共用体与枚举类型
☆☆ 第8章 结构体、共用体与枚举类型 17 8.1 结构体类型与结构体变量 ▪ 例8-3 使用指向结构体变量的指针访问输出结构体变量中各个 成员的值。 #include <stdio.h> #include <string.h> void main() { struct student { int num; char name[20]; char sex; int age; float score; }stu1={10001,"zhang",'M',19,88}; struct student *p=&stu1; printf("%d,%s,%c,%d,%6.2f\n",p->num,p->name,p- >sex,p->age,p->score); } ❖ 思考:如何输出班级n个学生的 信息?