C語言結構體定義

來源:酷知科普網 5.34K

學習C語言中,總結了 C語言結構體定義的三種方式,不敢獨享,在這裡分享自己的筆記,希望大家都能進步

操作方法

(01)1. 最標準的方式:#include <stdio.h>struct student  //結構體型別的說明與定義分開。 宣告{int age;   /*年齡*/float score;  /*分數*/char sex;     /*性別*/};int main (){struct student a={ 20,79,&#x27;f'}; //定義printf("年齡:%d 分數:%.2f 性別:%cn",, e,   );return 0;}

C語言結構體定義

(02)2 . 不環保的方式#include <stdio.h>struct student  /*宣告時直接定義*/{int age;   /*年齡*/float score;   /*分數*/char sex;      /*性別*//*這種方式不環保,只能用一次*/} a={21,80,'n'};int main (){printf("年齡:%d 分數:%.2f 性別:%cn", , e,   );return 0;}

C語言結構體定義 第2張

(03)3 最奈何人的方式#include <stdio.h>struct      //直接定義結構體變數,沒有結構體型別名。 這種方式最爛{int age;float score;char sex;} t={21,79,'f'};int main (){printf("年齡:%d 分數:%f 性別:%cn", , e, );return 0;}

特別提示

最好用標準的方式:第一種

熱門標籤