靚麗時尚館

位置:首頁 > 健康生活 > 心理

c語言結構型別宣告怎麼表達是否

心理2.76W
c語言結構型別宣告怎麼表達是否

結構體巢狀,賦初值,大括號巢狀就可以了。

問題是你程式碼寫錯了。

你定義的old1不是結構型別,而是結構變數。

在shuju中成員要寫struct old 變數名

不能寫struct old1。

下面是演示程式碼:(補充:如果想定義一個結構類型別名,要用typedef)

#include &ltstdio.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 %dn",,h,)

printf("結構變數shuju1中成員old1的初值:%d %d %dn",,h,)

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

return 0

}

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

typedef struct old

{

int year

int month

int day

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

)*/

標籤:宣告 語言