关于单链表的结点的创建问题

struct stu{
char sex;
int age;
struct stu next;
};
struct stu *p;
struct stu *ptr;
struct stu *head;
void main(){
head=(struct stu
)malloc(sizeof(struct stu));
head->age=12;
ptr=head;
for (int i=1; i printf("请输入数据:\n");
p=(struct stu*)malloc(sizeof(struct stu));
scanf("%d",&p->age);
p->next=NULL;
ptr->next=p;
ptr=ptr->next;
}
}
其中最后一行"ptr=ptr->next",我可以换成“ptr=p"吗?感觉两者好像没什么区别,求指教

可以改,没什么区别ptr->next=p;因为这一句先执行了

for循环漏了个括号。。。。


没区别,因为现在head的指针已经指向p