/*C語言 指向結構的指標*/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
struct data
{
char name[10];
int math, eng;
}student, *ptr;
ptr = &student;
printf("Student name:");
gets(ptr->name);
printf("Student math score:");
scanf_s("%d", &ptr->math);
printf("Student eng score:");
scanf_s("%d", &ptr->eng);
printf("Student name:%s\n", ptr->name);
printf("Student math score:%d\n", ptr->math);
printf("Student eng score:%d\n", ptr->eng);
printf("Average score:%d\n", (ptr->math + ptr->eng) / 2);
system("pause");
return 0;
}
結果為:
文章標籤
全站熱搜