二、结构体数组的初始化 如: struct student i int num; char name [20] char sex: int age; float score: char add [30 Stu[3]={1, m ZHANG",、M’,18,87.5,wWS Road"},{.},{.}
二、结构体数组的初始化 如:struct student { int num; char name[20]; char sex; int age; float score; char add[30]; } Stu[3]={{1,“ZHANG ” , ‘M’,18,87.5,“WS Road"},{…},{…}};
、举例 p266b2
三、举例 p266_b2
11.6指向结构体类型数据的指针 个结构体变量的指针就是该变量所占据的内存段的起始地址。 11.6.1指向结构体变量的指针 例3# include "string. h" main struct student ong int num; char name[20] char sex float score: K struct student stu l, *p p=&stu 1 stu 1. num=89101
11.6 指向结构体类型数据的指针 一个结构体变量的指针就是该变量所占据的内存段的起始地址。 11.6.1 指向结构体变量的指针 例3 #include “string.h" main() { struct student {long int num; char name[20]; char sex; float score;}; struct student stu_1,*p; p=&stu_1; stu_1.num=89101
strcpy(stu_1.name,” L i 1i n”); stu1.sex=′M’; stu 1 score=89.5: printf ("No: %ld\ nname: %s\sex: %c\n score:% f\n", stu 1. num, stu 1name, stu 1. sex, stu 1 score) printf("\nNo. :%1d\nname: %s\nsex: %c\nscore: %f\n (*p). num,(*p). name, (*. p). sex, (=*p). score 89101 cIlin?> M 89.5
strcpy(stu_1.name, ”Li lin”); stu_1.sex=’M’ ; stu_1.score=89.5; printf(”No:%ld\nname:%s\nsex:%c\nscore:% f\n” ,stu_1.num,stu_1.name,stu_1.sex, stu_1.score); printf("\nNo.:%1d\nname:%s\nsex:%c\nscore:%f\n", (*p).num,(*p).name,(*.p).sex,(*p).score); } p 89101 “Lilin” ‘M’ 89.5
说明: (*)表示p指向的结构体变量, (*p).num是p指向的结构体变量中的成员num p.num表示?
说明: (*p)表示p指向的结构体变量, (*p).num 是p指向的结构体变量中的成员num。 *p.num 表示?