1定義:
struct student {
? ? ? char name[100];
? ? ? ?int num[100];
};
注意結(jié)構(gòu)體是我們自己定義的變量募谎,所以結(jié)尾有個分號煤痕。相當(dāng)于int a;要加分號一樣他去。
2使用:
struct student point;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //為了簡便使用,可以定義時使用typedef關(guān)鍵字
typedef struct student student; ? ? ? ? ?//之后就可以直接使用student point;來定義一個新的變量了。
也可 typedef struct student {
? ? ? char name[100];
? ? ? ?int num[100];
}student; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//此處寫別名咕幻。
linux內(nèi)核中看到的結(jié)構(gòu)體
static const struct file_operations input_fops = {
.owner = THIS_MODULE,
.open = input_open_file,
};
//一直不明白為什么,初始化的時候要在前面加個點顶霞。 原來相當(dāng)于
input_fops.owner =?THIS_MODULE,
input_fops. open ?=? input_open_file,
//各個成員之間用逗號隔開肄程,上面的直接初始化了一個函數(shù)給open成員