语法*第九章*7 简单静态链表的创建

#include<stdio.h>
struct student{
   int num;
   float score;
   struct student *next;
} ;
 int main(void){
  struct student stu1,stu2,stu3;  /*定义3个struct student 类型的变量*/
  struct student *head,*p;/*定义2个指向struct student的指针*/
  stu1.num=18001;stu1.score=99.0;
  stu2.num=18002;stu2.score=91.0;
  stu3.num=18003;stu3.score=92.0;
  head = &stu1;
  stu1.next=&stu2;
  stu2.next=&stu3;
  stu3.next=NULL;
  p=head;
  do{
     printf("%d%5.1f\n",p->num,p->score);
     p=p->next;
  }while(p!=NULL);
}

猜你喜欢

转载自www.cnblogs.com/sunnybowen/p/8977147.html