(1) struct{ int x; int y; }test1; 好,定義了 結構 test1,test1.x 和 test1.y 可以在語句裡用了。(2) struct test {int x; int y; }test1; 好,定義了 結構 test1,test1.x 和 test1.y 可以在語句裡用了。與 1 比,省寫 了 test(3) typedef struct test {int x; int y; // 你漏打分號,給你添上 }text1,text2; 只說了 這種結構 的(類型)別名 叫 text1 或叫 text2真正在語句裡用,還要寫:text1 test1;然後好用 test1.x test1.y或寫 text2 test1;然後好用 test1.x test1.y(4)type struct {int x; int y; }test1;這個不可以。改 typedef ... 就可以了。但也同 (3)一樣,還要 寫:test1 my_st;才能用 my_st.x 和 my_st.y
struct{成員表列}變數名表列1,變數名表列2;(變數名表列1,變數名表列2)這2個變數名怎麼理解? 一個是聲明一個結構體的原始用法,一個是把結構體取了個別名。例如struct list{ int a; char c; stuct list *next;};(注意這個分號不能少)這個結構體的類型名是struct list ;struct只是聲明結構體需要的關鍵字。 如果你要定義一個結構體變數 你就可以 :結構體類型 變數名如:struct list student;你是不是覺得寫struct list 覺得很麻煩?那你就可以把struct list起個別名;就是綽號可以這樣struct list{ int a; char c; stuct list *next;};typedef struct list A;那麼你的A student; 就等同與 struct list student;。當然你也可以在聲明一個結構體的時候給它起別名typedef struct list{ int a;char c;struct list *next;}A;