私はこのレスポンスに困惑しています。誰かがこれを助け、私が間違っている箇所を指摘できますか?あなたがやっていることは、メモリの一部を割り当て、その場所(char *s
)を格納しているメモリがクローブされました
free(s); // cannot free constant "heel"
:codepadでの出力が「memory clobbered before allocated block
」
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char *s = (char *)malloc(10 * sizeof(char));
s = "heel";
printf("%s\n",s);
printf("%c\n",s[2]);
printf("%p\n",s);
printf("%d\n",s);
free(s);
return 0;
}
http://stackoverflow.com/questions/6571455/memory-clobbering-error –