[問題] typedef 加不加 struct 的差別

看板C_and_CPP作者 (眼睛都是數字)時間11年前 (2013/04/16 11:12), 編輯推噓3(303)
留言6則, 5人參與, 最新討論串1/1
考試的一個不懂的問題.... 程式碼: struct node{ int num; struct node *left; struct node *right; }; typedef struct node NodeStruct; typedef NodeStruct *NodePtr; 想請問一下,第六行的struct一定要加嗎? 加跟不加都可以Compile過,所以到底是? 另外底下的第七行*NodePtr為什麼要加*號呢? -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.71.170.202 ※ 編輯: kenwhz 來自: 203.71.170.202 (04/16 11:13)

04/16 11:16, , 1F
cl.exe /TC 原始碼.cpp
04/16 11:16, 1F

04/16 11:21, , 2F
1. C一定要 C++加不加都可以
04/16 11:21, 2F

04/16 11:22, , 3F
2. 因為是NodeStruct的指標 看成NodeStruct*比較好理解
04/16 11:22, 3F

04/16 11:47, , 4F
所以第七行的意思是 NodePtr等價於指向NodeStruct型態的結構?
04/16 11:47, 4F
※ 編輯: kenwhz 來自: 203.71.170.202 (04/16 11:48) ※ 編輯: kenwhz 來自: 203.71.170.202 (04/16 11:50)

04/16 11:57, , 5F
NodePtr 是指標,所指的型態為 NodeStruct
04/16 11:57, 5F
※ 編輯: kenwhz 來自: 203.71.170.202 (04/16 14:43)

04/16 18:00, , 6F
推二三樓
04/16 18:00, 6F
文章代碼(AID): #1HRC6nJt (C_and_CPP)