c語言struct用法

C語言struct用法 。 語法:struct 結構體名{ 結構體所包含的變量或數組};
需要這些哦
電腦
Dev C++
方式/
1鼠標點擊打開Dev C++軟件 , 如圖所示:

c語言struct用法



2打開之后 , 顯示如圖所示:
c語言struct用法



3點擊新建一個源代碼 , 如圖所示:
c語言struct用法



4然后鍵入如下代碼:
#include <stdio.h>
int main(){
    struct{
        char *name;  //姓名
        int num;  //學號
        int age;  //春秋
        char group;  //地點小組
        float score;  //成就
    } stu1;
    //給布局體所有當作員賦值
    stu1.name = "Tom";
    stu1.num = 12;
    stu1.age = 18;
    stu1.group = 'A';
    stu1.score = 136.5;
    //讀取布局體當作員的值
    printf("%s的學號是%d , 春秋是%d , 在%c組 , 本年的成就是%.1f!\n", stu1.name, stu1.num, stu1.age, stu1.group, stu1.score);
    return 0;
}
如圖所示:
c語言struct用法



5點擊運行 , 如圖所示:
c語言struct用法



6可以看到運行成果為:Tom的序號是12 , 春秋是18 , 在A組 ,
本年的成就是136.5
【c語言struct用法】如圖所示:
c語言struct用法




以上內容就是c語言struct用法的內容啦 , 希望對你有所幫助哦!

    猜你喜歡