程序设计C语言-静态链表及指针

程序设计C语言的学习笔记,静态链表的指针实现

struct Student
{
    int num;
    float score;
    struct Student *next;
};
struct Student stu_1, stu_2, stu_3, *head, *p;
stu_1.num = 10101;
stu_1.score = 89.5;
stu_1.next = &stu_2;

stu_2.num = 10103;
stu_2.score = 90;
stu_2.next = &stu_3;

stu_3.num = 10107;
stu_3.score = 85;
stu_3.next = NULL;

head = &stu_1;
p = head;
do {
    printf("Num: %d\nScore: %2.1f\n\n", p->num, (*p).score);
    p = p->next;
} while (p != NULL);

你可能感兴趣的:(程序设计C语言)