/*C語言 結構陣列*/
#include<stdio.h>
#include<stdlib.h>
#define i 2
int main(void)
{
    int j;

    struct data
    {
        char name[10];
        int score;
    }student[i] = { {"jackson", 87},
        {"Tommy", 78} };

    for (j = 0; j < i; j++)
        printf("student%d姓名:%s 分數:%d\n",
            j, student[j].name, student[j].score);
    printf("student[0]位元組:%d\n", sizeof(student[0]));
    //每個元素佔16個位元組。
    printf("student位元組:%d\n", sizeof(student));
    //每個元素佔16個位元組,兩個元素則位元組為32。


    system("pause");
    return 0;
}

結果為:

image

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

    愛學習

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