为什么下面的代码会给出分段错误?

时间:2019-12-22 14:53:56

标签: c

#if Is64Bit
    [DllImport(@"Resources/HIDAPI/x64/hidapi")]
#else
    [DllImport(@"Resources/HIDAPI/x32/hidapi")]
#endif
我尝试对链表进行编码,第一个“打印”功能用于打印每个索引,第二个功能“ printWantedIndice”是用于打印所需索引的功能。它给出了分段错误。我不明白为什么。你可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

以下是原因:

head->next->data = 44;

由于head->next未初始化,因此尝试访问它会遇到分段错误。

相关问题