鍊錶 共用體

2021-08-07 09:07:59 字數 1052 閱讀 1307

#define _crt_secure_no_warnings

#include

#include

#include

#define len sizeof(struct student)

//靜態鍊錶

struct student

;int main1()

while (p != null);

}//建立單向動態鍊錶

//思路:讓p1指向新開闢的結點,p2指向鍊錶中最後乙個結點,

//把p1所指的結點連線在p2所致的節點後面,用"p2->next=p1"

int n;

struct student *creat(void)//定義函式,此函式返回乙個指向煉表頭的指標

p2->next = null;

return head;

}//輸出鍊錶

void print(struct student * head)

while (p!=null);

}int main2()

//共用體

//共用體各成員的位址都是同一位址

int main3()

a; a.ch = 'a';

a.f = 1.5;

a.i = 40;

printf("%d\n", a.i);

printf("%c\n", a.ch);

printf("%f\n", a.f);

}//執行出錯!!!!!!!!!!!!!!!!!!!!!!why??????????????????????

union categ

;struct

person[2];//定義結構體陣列person,有兩個陣列

int main()

printf("\n"); printf("\n"); printf("\n");

for ( i = 0; i < 2; i++)

system("pause");

return

0;}

Day 15 結構體,共用體, 列舉,鍊錶 。

1.結構體 結構體是使用者自己定義的一種資料結構。c語言中是允許使用者自己定義資料型別的。它是使用者將不同的基本資料型別組合在一起,構成的一種新的資料型別。這些組合在一起的資料型別是相互聯絡的。這種結構體的寫法,對於有時候的引用會非常方便。struct student 記得要加封號 此齣結構體 st...

結構體 共用體

結構體 結構體的定義1 struct mystruct 定義新變數 struct mystruct s1 結構體定義2 typedef struct mystruct mstrct 定義新變數 mstrct s1 結構體定義3 type struct mstrct 定義新變數 mstrct s1 共...

共用體詳解

共用體同結構體的定義形式上相同,只是把關鍵字struct改為union。有時需要把幾種不同型別的變數放在同有一記憶體區域中,見圖12 6,把乙個整型變數,乙個字元變數,乙個實型變數放在同一記憶體區域中,儘管三個變數占用位元組數各不相同,但起始位址都一樣 例如1000 它要用 覆蓋 技術,使多個變數互...