Syntax *Chapter 9*7 Creation of Simple Static Linked List

#include<stdio.h>
struct student{
   int num;
   float score;
   struct student *next;
} ;
 int main( void ){
   struct student stu1,stu2,stu3;   /* Define 3 variables of type struct student */ 
  struct student *head,*p; /* Define 2 pointers to 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);
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325216996&siteId=291194637