當前位置:妙知谷 >

遊戲數碼 >電腦 >

C語言結構體定義

C語言結構體定義

學習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;}

特別提示

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

標籤: 語言
  • 文章版權屬於文章作者所有,轉載請註明 https://miaozhigu.com/sm/diannao/m2k7rq.html