e******d 发帖数: 14 | 1 void func(void)
{
char *str = (char *) malloc(100);
strcpy(str, “"hello");
free(str);
if(str != NULL)
{
strcpy(str, “"world");
printf("%s\n", str);
}
}
The output is "world" on linux. The freed memory still can be accessed? | d*******d 发帖数: 2050 | 2 yes.
free means it can be used again. but it won't garantee to be reset to 0.
but it is very very dangerous.
【在 e******d 的大作中提到】 : void func(void) : { : char *str = (char *) malloc(100); : strcpy(str, “"hello"); : free(str); : if(str != NULL) : { : strcpy(str, “"world"); : printf("%s\n", str); : }
|
|