當前位置:首頁 » 編程語言 » c語言結構體嵌套

c語言結構體嵌套

發布時間: 2023-06-15 14:15:34

㈠ C語言 如何在結構體中給嵌套的結構體賦值

結構體嵌套,賦初值,大括弧嵌套就可以了。
問題是你代碼寫錯了。
你定義的old1不是結構類型,而是結構變數。
在shuju中成員要寫struct old 變數名;
不能寫struct old1。
下面是演示代碼:(補充:如果想定義一個結構類型別名,要用typedef

#include <stdio.h>

struct old

{

int year;

int month;

int day;

}old1={1972, 8, 3};

struct shuju

{

char name[10];

char gender[6];

int height;

struct old old1;

char access[9];

}shuju1={"moumouren","male",175,{2019,6,29},"well"};

int main()

{

printf("結構變數old1的初值: %d %d %d ",old1.year,old1.month,old1.day);

printf("結構變數shuju1中成員old1的初值:%d %d %d ",shuju1.old1.year,shuju1.old1.month,shuju1.old1.day);

printf("我特意起一樣的名字,就是告訴你這兩個變數是不一樣的。 ");

return 0;

}

/*(補充:如果想定義一個結構類型別名,要用

typedef struct old

{

int year;

int month;

int day;

}old1;//這樣old1才表示是一個類型,然後再定義該類型變數時,才可以寫 old1 變數名;

)*/

熱點內容
安卓開發選哪個版本的SDK 發布:2025-07-02 22:19:07 瀏覽:485
未上傳圖片 發布:2025-07-02 22:14:01 瀏覽:598
安卓qq直播怎麼分享聲音 發布:2025-07-02 22:13:21 瀏覽:249
安卓系統怎麼刷機清除內存 發布:2025-07-02 22:08:19 瀏覽:696
安卓手機6位數密碼有多少組 發布:2025-07-02 21:50:31 瀏覽:797
存儲卡視頻多了 發布:2025-07-02 21:49:40 瀏覽:850
ajax無刷新上傳圖片 發布:2025-07-02 21:32:56 瀏覽:117
編譯器不認pow函數 發布:2025-07-02 21:27:04 瀏覽:339
w10隱藏文件夾 發布:2025-07-02 21:27:03 瀏覽:534
電腦d盤拒絕訪問 發布:2025-07-02 21:27:02 瀏覽:779