測試**:
#include
#include
int main() ;
struct student *p, *q, *r, *current;
p = (struct student *)malloc(sizeof (struct student));
q = (struct student *)malloc(sizeof (struct student));
r = (struct student *)malloc(sizeof (struct student));
p->name = "bright";
p->score = 98;
q->name = "linda";
q->score = 95;
r->name = "jenny";
r->score = 95;
p->next = q;
q->next = r;
r->next = null;
current = p;
printf("students:\n");
while (current != null)
free(p);
free(q);
free(r);
return 0;
}=== 測試結果:
students:
bright 98
linda 95
jenny 95
C語言中結構體 自引用 和 相互引用
technorati 標籤 c語言,結構體,自引用,相互引用,self reference,mutual reference 結構體的自引用 self reference 就是在結構體內部,包含指向自身型別結構體的指標。結構體的相互引用 mutual reference 就是說在多個結構體中,都包含...
C語言中結構體 自引用 和 相互引用
結構體的自引用 self reference 就是在結構體內部,包含指向自身型別結構體的指標。結構體的相互引用 mutual reference 就是說在多個結構體中,都包含指向其他結構體的指標。1.1 不使用typedef時 錯誤的方式 1 struct tag 1 這種宣告是錯誤的,因為這種宣告...
C語言中結構體 自引用 和 相互引用
結構體的自引用 self reference 就是在結構體內部,包含指向自身型別結構體的指標。結構體的相互引用 mutual reference 就是說在多個結構體中,都包含指向其他結構體的指標。1.1 不使用typedef時 錯誤的方式 1 struct tag 1 這種宣告是錯誤的,因為這種宣告...