我刚刚开始学习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;
}