看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Dev C 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) GCC 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) stdio.h stdlib.h 問題(Question): 小弟我略懂linked list 知道怎麼建linked list, 也知道要用malloc/free 但是想問說為什麼當不使用malloc時 建單一linked list node時 無法使用struct pointer存取資料 餵入的資料(Input):預期的正確結果(Expected Output): 程式順利跑完 錯誤結果(Wrong Output): 執行時程式當機停止運作 程式碼(Code):(請善用置底文網頁, 記得排版) #include <stdio.h> #include <stdlib.h> typedef struct ns{ int value; struct ns* next; }Node; int main() { Node* list; list->value = 3; list->next = NULL; printf("list value:%d\n",list->value); printf("End test\n"); system("pause"); return 0; } 補充說明(Supplement): 無 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.220.144.147 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1508488818.A.FB6.html
caras: 置底十三戒之第三戒 10/20 16:47
kokal: Node* list;是建一個pointer, 指向垃圾地址 10/20 16:50
stupid0319: 沒空間概念,沒指標觀念,指標章節再重念10遍 10/20 16:52
yamakazi: orz 了解了 謝謝 10/20 16:53
worcdlo: 也沒有記憶體觀念 10/20 18:09
worcdlo: 加油 10/20 18:09
Hazukashiine: singly linked list 10/20 18:23
nova06091: https://repl.it/MxJv 10/20 18:38
boss0405: ...先把指標搞懂再看LinkedList吧,不要越級打怪 10/20 20:40
jimfan: Node* list; 沒有建立任何 node呀 10/21 19:24
jimfan: 其他樓主有點嚴苛,但也真確;請君繼續努力,加油加油 10/21 19:25
nylon419: Node* list; <== 沒有初始化,編譯器不知道給它啥東西 10/26 17:02
friendever: output: segmentation fault 11/09 07:42