當前位置:首頁 » 編程語言 » 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 變數名;

)*/

熱點內容
ftp伺服器被動模式配置 發布:2025-07-04 05:17:32 瀏覽:331
電動車小龜有哪些配置 發布:2025-07-04 05:16:18 瀏覽:39
mysql同步存儲過程 發布:2025-07-04 05:14:32 瀏覽:662
安卓手機如何控制空調 發布:2025-07-04 05:09:06 瀏覽:154
新潔爾滅用於物體表面怎麼配置 發布:2025-07-04 05:03:28 瀏覽:829
生活中的雲伺服器 發布:2025-07-04 05:01:55 瀏覽:744
三星g6700c原始密碼是多少 發布:2025-07-04 04:49:41 瀏覽:726
網頁編程代碼 發布:2025-07-04 04:47:25 瀏覽:805
發消息時用到什麼密碼 發布:2025-07-04 04:41:47 瀏覽:980
3個密碼箱能裝多少錢 發布:2025-07-04 04:39:36 瀏覽:11