<分区>
我刚开始学习 c 中的链表。我仍然混淆代码中的第 1 行。 1.什么是temp->data,是指针吗?多变的? 2.什么是temp->next=head,这里的head有NULL值????如果是这样,temp->next 现在变为 NULL ??? 请真的搞砸了这条线,帮帮我。谢谢
#include <stdio.h>
#include <stdlib.h>
struct test_struct{
int data;
struct test_struct *next;
};
struct test_struct* head=NULL;
int main()
{
head = NULL;
struct test_struct* temp = (struct test_struct*)malloc(sizeof(struct test_struct));
if(NULL==temp)
{
printf("error in memory");
return 0;
}
temp->data=5; // line 1 <---------- what's going on
temp->next=head; // line 2 <---------- what's going on here?
head=temp;
printf("%p\n",head);
return 0;
}