小编And*_*rew的帖子

打印链接列表时出现分段错误

我一直在阅读链接列表的斯坦福教程.我使用了一个创建三个数字(1,2,3)列表的函数.函数本身不打印结果,所以我决定自己测试一下.但是,当我运行它时,它会给我分段错误.

话虽如此,当我删除该函数并将代码复制到main时,它可以工作.有人可以解释为什么主要功能不起作用?

这是给我分段错误的代码:

#include <stdio.h>
#include <stdlib.h>

      struct node {
         int            data;
         struct node*   next;
};

struct node* BuildOneTwoThree() 

{
   struct node* head = NULL;
   struct node* second = NULL;
   struct node* third = NULL;
   head = malloc(sizeof(struct node));
   second = malloc(sizeof(struct node));
   third = malloc(sizeof(struct node));

head->data = 1;
head->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = NULL;

return head;

}


int main()

{
   struct node* head;
   struct node* second;
   struct node* third; …
Run Code Online (Sandbox Code Playgroud)

c printf linked-list segmentation-fault

2
推荐指数
1
解决办法
332
查看次数

addq 和 movl 的区别,然后是 addq

两者之间的功能区别是什么

addq (%rbx), %rax

和

movl (%rbx), %ecx addq %rcx, %rax

在组装?

我认为他们做同样的事情,但功能上的区别是什么?

assembly x86-64

2
推荐指数
1
解决办法
7729
查看次数

标签 统计

assembly ×1

c ×1

linked-list ×1

printf ×1

segmentation-fault ×1

x86-64 ×1