静态链表错哪了?


#include "stdio.h"

 struct student

    {

    long num;

    float score;

    struct student * next;

    };

void main()

{

    struct student stu1,stu2,stu3;

    struct studentn * head,*p;

    stu1.num=001;stu1.score=56;

    stu1.num=002;stu1.score=77;

    stu1.num=003;stu1.score=99;

    head=&stu1;

    stu1.next=&stu2;

     stu2.next=&stu3;

     stu3.next=NULL;

    p=head;

    while(p!=NULL)

    {

    printf("%ld,%5.1f\n",p->num,p->score);

    p=p->next;

    }

   }



溯源1
浏览 1030回答 1
1回答

岂可奈何

定义结构体指针时  student  写成 studentn定义成员变量是,全部是  stu1的,没有stu2和stu3程序:#include <stdio.h> struct student    {    long num;    float score;    struct student * next;    };void main(){    struct student stu1,stu2,stu3;    struct student * head,*p;    stu1.num=001;stu1.score=56;    stu2.num=002;stu2.score=77;    stu3.num=003;stu3.score=99;    head=&stu1;    stu1.next=&stu2;    stu2.next=&stu3;    stu3.next=NULL;    p=head;    while(p!=NULL)    { printf("%ld,%5.1f\n",p->num,p->score); p=p->next;    }}
打开App,查看更多内容
随时随地看视频慕课网APP