输出三个学生中成绩最高的学生信息
1>
#include<stdio.h>
typedef struct student
{
int num;
char name[10];
int score;
} Student;
int main()
{
Student s1,s2,s3,max;
scanf("%d %s %d",&s1.num,s1.name,&s1.score);
scanf("%d %s %d",&s2.num,s2.name,&s2.score);
scanf("%d %s %d",&s3.num,s3.name,&s3.score);
max=s1;
if(max.score<s2.score) max=s2;
if(max.score<s3.score) max=s3;
printf("%d %s %d",max.num,max.name,max.score);
}
2> 结构体指针;
#include<stdio.h>
typedef struct student
{
int num;
char name[10];
int score;
} Student;
int main()
{
Student s1,s2,s3,*p;//*p,结构体指针
scanf("%d %s %d",&s1.num,s1.name,&s1.score);
scanf("%d %s %d",&s2.num,s2.name,&s2.score);
scanf("%d %s %d",&s3.num,s3.name,&s3.score);
p=&s1;
if(p->score<s2.score) p=&s2;
if((*p).score<s3.score) p=&s3;//p->和(*p).相同;
printf("%d %s %d",p->num,p->name,(*p).score);
}
访问成员变量三种方式:s1.score,p->score,(*p).score;
结构体初始化:
student s1={1001,lingming,98};
*p=NULL;