有人可以请我解释一下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