参考:

LEETCODE 中的member access within null pointer of type 'struct ListNode'

解决 leetcode 编译问题:Line x: member access within null pointer of type 'struct TreeNode'

在leetcode上提交代码后出现编译错误:

Line x: member access within null pointer of type 'struct TreeNode'

原因:在测试过程中,第x行访问的指针为NULL,通常情况下表明程序未对NULL情况作出判断。例如:

int val = root->next->val;

在这一行中,没有加入rootroot->next是否为空的判断,因此需修改为:

if (root != NULL) {
    if (root->next != NULL) {
        int val = root->next->val;
    }
}

2018.7

相关文章:

  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
  • 2021-11-01
  • 2021-10-23
  • 2022-12-23
  • 2021-12-06
  • 2021-11-09
猜你喜欢
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
相关资源
相似解决方案