gpt4 book ai didi

c - 如何在C中显示链表中节点的地址

转载 作者:太空宇宙 更新时间:2023-11-04 05:19:11 25 4
gpt4 key购买 nike

void insert_end()
{
struct node *nn=(struct node*)malloc(sizeof(struct node));
printf("Enter the data:");
scanf("%d",&nn->info);
nn->next=NULL;
if(first==NULL)
{
first=nn;
first->next=first;
}
else
{
temp=first;
while(temp->next!=first)
temp=temp->next;
temp->next=nn;
nn->next=first;
printf("The address of the first node is %d", first);
printf("The address of the last node is %d", nn->next);
}
}

这是一个循环链表,C语言的插入函数。

我需要证明第一个节点的地址和最后一个节点的链接部分有相同的值,从而证明它是一个循环链表。

但是我上面的代码给出了随机整数值..!

最佳答案

您可能希望使用 %p 打印地址

    printf("The address of the first node is %p",first);
printf("The address of the last node is %p",nn->next);

关于c - 如何在C中显示链表中节点的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19835826/

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