我正在 Linux 上構建一個 C 測驗程式。
為什么下面這段代碼編譯失敗?Afterlist_t是型別定義的,編譯器不應該稍后理解它與 a 的型別相同struct list嗎?
嘗試使用 malloc() 創建新串列項失敗error: invalid type argument
#include <stdio.h>
#include <stdlib.h>
typedef struct list
{
struct list *next_ptr;
int value;
}list_t;
int main()
{
list_t myList;
myList->next_ptr = malloc(sizeof(list_t)); // This fails
return 0;
}
uj5u.com熱心網友回復:
myList->next_ptr應該是myList.next_ptr因為myList不是指標。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/516834.html
標籤:C指针结构链表宣言
上一篇:使用指標分配特定的記憶體地址
