结构体数组应用举例 s[U score[3]=s[]. score [o]+s[i]. score[1]+s[i]. score [2])/37 printf("aVerage for(i=0;<N;+) printf("%d,s[i]. score 3) max =s[O].score 3]; k=0 for(i=1; i<N; i ++ if(s[j]. score [3]>max {k=i; max=s. score 3] printf (\ n the top student: printf("%d, %S, %d, %d, %d average: %d\n"s[k] name, s[k]. score[O] sk].scorel1l, slk].score[2], s[k]. score 3]); 1
结构体数组应用举例 s[i].score[3]=(s[i].score[0]+s[i].score[1]+s[i].score[2])/3; } printf(“\nAverage:”); for(i=0;i<N;i++) printf(“%d”, s[i].score[3]); max =s[0].score[3]; k =0; for (i=1;i<N;i++) if(s[i].score[3]>max) { k = i; max = s[i].score[3]; } printf (“\n The top student :”); printf (“%d,%s,%d, %d, %d,average:%d\n”,s[k].name, s[k].score[0], s[k].score[1], s[k].score[2], s[k].score[3]);}
结构体和指针 存放结构体变量在内存的起始地址 指向结构体变量的指针 ·定义形式: struct结构体名*结构体指针名 例 struct student*p; ◆使用结构体指针变量引用成员形式 (*结构体指针)成员结构体指针>成员分结构体变量.成员 指向远算符 优先级:1 结合方向:从左向右
结构体和指针 – 指向结构体变量的指针 • 定义形式:struct 结构体名 *结构体指针名; 例 struct student *p; ❖使用结构体指针变量引用成员形式 存放结构体变量在内存的起始地址 指向运算符 -> 优先级: 1 结合方向:从左向右 (*结构体指针).成员 结构体指针->成员 结构体变量.成员