C語言 結構體快速學習

2021-10-21 06:32:36 字數 1476 閱讀 9028

struct teacher

;

struct teacher teacher1;
struct teacherteacher1, teacher2, teacher3,

*teacher4;

struct teacher teacher1 =

;

struct teacherteacher1 =

;

#include

#include

struct teacher

;int

main()

;struct teacher* teacher2 =

&teacher1;

printf

("name: %s\nage: %d\nemail:%s\n"

, teacher1.name, teacher1.age, teacher1.email)

;printf

("name: %s\nage: %d\nemail:%s\n"

, teacher2->name, teacher2->age, teacher2->email)

;return0;

}

可以使用賦值操作符=將結構體a賦值給結構體b.

teacher3 = teacher1;
結構體的資料成員也是結構體。

struct studentscore;

struct infostructinfo;

};

struct scorestruct

;struct infostruct

;struct student

;

說明

結構體a中定義結構體b,則在結構體a外是不可見的,即:只能在a中宣告b的結構體變數。

struct student 

;struct infostruct ;}

;

和下邊的**等價

struct student 

;

不指定結構體名稱,但是需要至少宣告乙個結構體變數。

可直接訪問(person1.name),但是以後的程式中不能宣告這種型別的變數。

struct

person1, person2;

C語言 結構體學習

為什麼需要結構體 為了表示一些複雜的事物,而普通的基本型別無法滿足實際要求 什麼叫結構體 把一些基本型別資料組合在一起形成的乙個新的復合資料型別 如何定義乙個結構體 3中方式 推薦使用第一種 第一種方式 這只是定義了乙個新的資料型別 並沒有定義變數 struct student 第二種方式 stru...

C語言學習 結構體

include include include 宣告結構體 struct student student結構體名 int age char int main 初始化結構體變數 bbbb strcpy s1.name,bbbb s1.age 22 s1.m 列印結構體變數,逐個列印 printf s ...

C語言學習 結構體

題目要求 學生的記錄由學號 姓名 專業組成,根據班級人數,將學生記錄存放在結構體陣列中,由於部分同學轉專業,學生記錄發生了變化,請程式設計實現根據學號查詢查詢學生並修改專業,分別輸出轉專業和未轉專業的學生記錄。要求 班級人數 學生記錄均由鍵盤輸入 include define m 100 要求 1....