有人可以請我解釋一下free(test[0])
給我一個segmentation fault (core dumped)
?我試圖評論免費,然後程序正確終止(除了丟失的內存)。另外,如果我註釋掉test[0] = "abcd"
並再次插入free(...)
它也會正確終止!c免二維數組給出分段錯誤
char **test = (char**) (malloc(sizeof(char*) * 5));
for (int i=0; i<5; i++) {
test[i] = (char*) (malloc(sizeof(char*) * 5));
}
test[0] = "abcd";
free(test[0]);
[不要投出malloc的結果](http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc) – OlivierLi