1 题目
功能:指向结构体变量的指针
描述:通过结构体指针变量实现显示学生信息
2 思路
熟悉结构体的使用
熟悉指针和结构体的混合使用
3 代码
#include <stdio.h>
/**
功能:指向结构体变量的指针
描述:通过结构体指针变量实现显示学生信息
**/
struct student {
int num;
char name[20];
char sex;
int age;
float score;
};
int main(int argc, char const *argv[]) {
struct student stu = {
1001, "计算广告生态", 'M', 28, 98.5
};
struct student *s = &stu;
printf("No.\t%d\n", s->num);
printf("Name.\t%s\n", s->name);
printf("Sex.\t%c\n", s->sex);
printf("Age.\t%d\n", s->age);
printf("Score.\t%d\n", s->score);
}
示例结果:
$ gcc ex012.c -o demo
$ ./demo
No.1001
Name.计算广告生态
Sex.M
Age.28
Score.73896