C語言入門 結構體的概要

2022-04-09 14:27:09 字數 3343 閱讀 3401

1

/*note:your choice is c ide

*/2 #include "

stdio.h"3

//結構體。 4//

什麼是結構體。什麼時候使用5//

1.結構體型別的概念6//

由不相同資料型別和相同資料型別 共同組成的資料集合。7//

基本資料型別: int float char double8//

構造資料型別: 陣列 結構體 共用體(聯合體) 列舉9//

2.結構體變數的定義

10//

結構體型別(struct) 結構體名(識別符號)

11//

變數名列表;

15//

結構體 既可以定義為 全域性變數 也可以定義為 區域性變數

16//

3.結構體變數的引用

17//

4.結構體型別的初始化

18//

5.結構體是可以巢狀定義的。

19struct

student

20stu=,asd,qwe,r;//

stu 為結構體 使用的名字。 第一種給結構體 起名的方法, 是使用 提示輸入

2425

void

main()

26;//

結構體的宣告時 初始化賦值

29 printf("

請輸入這個學生的姓名:");

30 scanf("%s"

,stu.name);

31 printf("

請輸入這個學是的學習效果:");

32 scanf("

%d",&stu.tk);//

%d %c %f 需要加&

33//

%s 只需要加陣列的名字 ,陣列的名字 是陣列的首位址。

34 printf("

這個學生的姓名為:%s,學習效果為:%d\n

",stu.name,stu.tk);

35 printf("

第二名學生的姓名為:%s,學習效果為:%d\n

",stu1.name,stu1.tk);

36 }

1

/*note:your choice is c ide

*/2 #include "

stdio.h

"3 #include "

string.h"4

//結構體的應用。 5//

1.利用兩個結構體的某乙個內部成員 進行 加減乘除。6//

是定義兩個結構體 方便 7//

還是 定義乙個結構體 寫兩個名字 方便。

8struct

student

9ls=,lb=;

13void

main()

14

1

/*note:your choice is c ide

*/2 #include "

stdio.h"3

//結構體 陣列

4struct

student

5qwer[3

]; 9

void

main()

1023 printf("

\n----------------------------------\n");

24for(i=0;i<3;i++)

2529 printf("

這3名總額度為:%d

",sum);

30 }

1

/*note:your choice is c ide

*/2 #include "

stdio.h"3

//結構體 陣列

4struct

student

5qwer[5]=,,,,};9//

根據學號的奇偶數 把名字分開,並輸出。

10//

奇數號 輸出 存放在乙個結構體陣列中 並排序大=》小 輸出 整個結構體的內容

11//

偶數號 輸出 存放在乙個結構體陣列中 並排序小-》大 輸出

12void

main()

1325

else

2631}32

33 printf("

先輸出偶數陣列\n");

34for(i=0;i)

3538 printf("

\n在輸出 奇數陣列\n");

39for(i=0;i)

4043 }

1

/*note:your choice is c ide

*/2 #include "

stdio.h"3

struct

student

4stu=;

8void print(struct student stu)//

結構體列印函式913

14void

main()

15

1

/*note:your choice is c ide

*/2 #include "

stdio.h"3

struct

student

4stu[5]=,,,,};89

void dy(struct student stu,int

len)

101617}

18void

main()

19

1

/*note:your choice is c ide

*/2 #include "

stdio.h"3

struct

student

4stu;

10//

結構體的位元組數 等於 結構體內部各成員位元組數總和。

1112

//在結構體/共用體中 有乙個規則 短型別 會向長型別 補齊。

13void

main()

14

1

/*note:your choice is c ide

*/2 #include "

stdio.h"3

//共用體 也叫聯合體。4//

共用體內 所有成員都會共用最長成員的位址。 856

7//共用體。

8union data

9da;

1415

void

main()

16

C語言入門 函式的概要

函式 一。什麼是函式 函式的概念 具有特定功能的模組。二。什麼是函式呼叫。用別人寫好的 函式名 就叫函式的呼叫。三。什麼是引數 函式之間傳遞的資料。四。函式的組成部分 函式首 void main 引數列表 函式體 函式的分類 1.從定義角度 自定義函式 人為定義的函式 庫函式 系統定義函式 prin...

C語言入門 函式的概要

note your choice is c ide include stdio.h include windows.h 標頭檔案 倉庫 void gbtc 函式首 函式型別 函式名 void main 主調函式 note your choice is c ide include stdio.h 值傳...

C語言入門 結構體 檔案的應用

1 note your choice is c ide 2 include stdio.h 3 void main 416 4.讀 寫操作 核心 這裡 寫裡放任何學過的東西。只要型別對,可以存裡 17 printf 請輸入一段話 18 scanf s name 19 fprintf fp,俊哥剛才寫...