struct Student stu_1; // define a variable of type struct Student stu_1 struct Student * P; // defined data type struct Student point pointer variable P = & stu_1; // P point stu
If p points to a structure variable stu equivalent:
(1) stu. Member name (such as stu.num)
(2) (* p). Member Name (such as (* p) .num)
(3) p-> member name (e.g., p-> num)
1 //输出最高成绩 2 3 #include<stdio.h> 4 #define N 3 5 struct Student 6 { 7 int num; 8 char name[20]; 9 float score[3]; 10 float aver; 11 }; 12 void input(struct Student stu[]); 13 struct Student max(struct Student stu[]); 14 void print(struct Student stu); 15 int main () 16 { . 17 struct Student STU [N], * P = STU; 18 is INPUT (P); . 19 Print (max (P)); 20 is return 0 ; 21 is } 22 is void INPUT ( struct Student STU [] ) 23 is { 24 int I; 25 the printf ( " Please enter the respective student information: number, name, three courses results: \ n- " ); 26 is for (I = 0 ; I <N; I ++ ) 27 { 28 Scanf ( '%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]); 29 stu[i].aver=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;//求平均值 30 } 31 } 32 struct Student max(struct Student stu[]) 33 { 34 int i,m=0; 35 for(i=0;i<N;i++) 36 { 37 [ IF (STU [I] .aver> STU [m] .aver) m = I; 38 is } 39 return STU [m]; 40 } 41 is void Print ( struct Student Stud) 42 is { 43 is the printf ( " \ n-highest score is \ n- " ); 44 is the printf ( " % D " , stud.num); 45 46 is }