#询问下C语言在while语句的循环中定义结构体变量指针的问题
第20行和第23行这里每循环一次就重复定义一次结构体指针p和尾指针last,就相当于执行了n次定义了n个p,但是为什么不会报错?
代码如下
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
typedef struct _node{
int num;
struct _node *next;
}node;
int main()
{
int t;
node *head = NULL;
do{
scanf("%d",&t);
if(t!=-1)
{
node * p=(node*)malloc(sizeof(node));
p->num=t;
p->next=NULL;
node *last= head;
if(last){
while(last->next){
last=last->next;
}
last->next=p;
}else
{
head=p;
}
}
}while(t!=-1);
node *q=head;
while(q->next)
{
printf("%d\n",q->num);
q=q->next;
}
}