網站首頁 健康小知識 母嬰教育 起名 運動知識 職場理財 情感生活 綠色生活 遊戲數碼 美容 特色美食 愛好
當前位置:酷知知識幫 > 遊戲數碼 > 電腦

C語言結構體定義

欄目: 電腦 / 發佈於: / 人氣:5.03K

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

操作方法

(01)1. 最標準的方式:#include <stdio.h>struct student  //結構體類型的説明與定義分開。 聲明{int age;   /*年齡*/float score;  /*分數*/char sex;     /*性別*/};int main (){struct student a={ 20,79,'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;}

特別提示

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

Tags:語言