当前位置: 移动技术网 > IT编程>开发语言>C/C++ > //指针的进一步理解

//指针的进一步理解

2018年06月29日  | 移动技术网IT编程  | 我要评论

5252bbb,普通话水平测试题,李雪主的前夫被曝光

#include "stdio.h"
#include "stdlib.h"
#define SIZE 4
struct student
{
    int num;
    struct student *next;
}stu[SIZE];

main()
{
    struct student *h=NULL,*q,*tail;
    int i=0;
    while(i<SIZE)
    {

      tail=(struct student *)malloc(sizeof(struct student));
     if(h==NULL)
          h=tail;//记录开始的值,输出时使用;但是不能中途赋值从中间开始输出,因为节点结构是一个整体
     else
         q->next=tail;
     q=tail;
     scanf("%d",&tail->num);
     tail->next=NULL;
     i++;
    }
    q=h;//需要一个头指针让q回到开头 q= ,否则q的值是最后输入的值,所以 q=q->next; 过后q=NULL 输出结束;
    while(q)
    {
        printf("%d ",q->num);
        q=q->next;
    }
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网