C语言结构体指针

内容仅供自己学习使用。

#include<stdio.h>
#include<string.h>
struct student
{
int num;
char name[20];
char sex;
float score;
};
void input(struct student *point)
{
(*point).num=100;
strcpy((*point).name,"Dad");
(*point).sex='M';
(*point).score=101.5;
}
void output(struct student *point1)
{
printf("%d\n%s\n%c\n%f\n",point1->num,point1->name,point1->sex,point1->score);
}
int main()
{

struct student stu1,stu2;

input(&stu1);
output(&stu1);

stu2.num=100;
strcpy(stu2.name,"SUN");
stu2.sex='M';
stu2.score=80.5;

struct student *point3;
point3=&stu2;

printf("%d\n",(*point3).num);
printf("%s\n",(*point3).name);
printf("%c\n",(*point3).sex);
printf("%f\n",(*point3).score);

return 0;
}

posted @ 2021-08-21 09:39  吃辣的鱼儿  阅读(58)  评论(0)    收藏  举报