/*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;
}

結果為:

image

arrow
arrow
    創作者介紹
    創作者 愛學習 的頭像
    愛學習

    愛學習

    愛學習 發表在 痞客邦 留言(0) 人氣()