void* heap = malloc(100);
char *c = heap;
strcpy(c, "Terence");
printf("heap = %s\n", heap);
free(heap);
heap = malloc(100);
printf("heap = %s\n", heap);
输出是:
heap = Terence
heap =
这是我所期望的,但现在我有一个复杂得多的代码,结构与上面类似,但输出如下:
heap = "Terence"
heap = " ren "
类似的东西。
好像堆还没有清理干净?
有没有办法解决它?