參考:
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;
在這一行中,沒有加入root
及root->next
是否為空的判斷,因此需修改為:
if (root != NULL) {
if (root->next != NULL) {
int val = root->next->val;
}
}
2018.7