1 #include <stdio.h>
2 struct student
3 {
4 int num;
5 float score;
6 struct student*next;
7 };
8 int main()
9 {
10 struct student a,b,c,*head,*p;
11 a.num=10101;a.score=89.5;
12 b.num=10103;b.score=90;
13 c.num=10103;c.score=90;
14 head=&a;
15 a.next=&b;
16 b.next=&c;
17 c.next=NULL;
18 p=head;
19 do{
20 printf("%ld%5.1f\n",p->num,p->score);
21 p=p->next;
22 }while(p!=NULL);
23 return 0;
24 }
head指向a的结点,a.next指向b的结点·······c.next=null是为了不让其指向任何存储单元
需要定义一个指针变量来接受head的地址
本程序所有节点都是在程序中定义的所以用完后不能释放,为静态链表
来源:https://www.cnblogs.com/ZJK132/p/12283764.html