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 "
类似的东西。
它似乎堆没有被清理?
有没有办法解决它?
或者,对于字符串的缓冲区,只需将第一个字节设置为零即可。 –