2014年7月27日 星期日

[C/C++] typedef 結構


#include <stdio.h>
#include <stdlib.h>

struct data
{
    char name[10];
    int math;
};

typedef struct data SCORE;  // 把 struct data 定義成新的型態

void display(SCORE);        // 宣告函數 display() 的原型

int main(void)
{
    SCORE s1={"Jenny", 74};
    display(s1);            // 呼叫 display() , 傳入結構變數 s1

    system("pause");

    return 0;
}

void display(SCORE st)      // 定義函數 display()
{
    printf("學生姓名: %s\n", st.name);
    printf("數學成績: %d\n", st.math);
}


參考出處:C語言教學手冊

沒有留言:

張貼留言