gpt4 book ai didi

c - c 中的链接列表,代码行的解释?

转载 作者:太空宇宙 更新时间:2023-11-04 06:00:39 24 4
gpt4 key购买 nike

<分区>

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com