在写一个 链表 相关的题目时犯的错误。

runtime error: member access within misaligned address 0xbebebebebebebebe for type 'struct ListNode', which requires 8 byte alignment (ListNode.c)
0xbebebebebebebebe: note: pointer points here

这是为啥呢;因为没有赋初值

假设这么个结构体

struct ListNode {
    int val;
      struct ListNode *next;
  };

你创建一个结构体变量,这样才正确

struct ListNode *p,*q;
p=(struct ListNode * )malloc(sizeof(struct ListNode));
p->next=NULL;

如果不给p赋初值的话会报这个错!

再多嘴一句,创建结构体记得加struct

struct ListNode *p;

p=(struct ListNode * )malloc(sizeof(struct ListNode));

更多推荐

报错runtime error: member access within misaligned address(以及结构体使用)