请教高手问题拉
char *str = (char *) malloc(100);
strcpy(str, "hello");
free(str);
if(str != NULL)
{
strcpy(str, "world");
printf(str);
}
问题1 : 在free后没有置为null,str虽然是野指针了,但是还是指向原来的地址,所以strcpy(str, "world")后输出应该是world吧,为啥输出是乱码啊
问题2 : 我在第三行插入printf(str)变成以下代码后,就能输出helloworld,也就是说第二个printf如我意想的那样"正常"输出了,谁能解释一下
char *str = (char *) malloc(100);
strcpy(str, "hello");
printf(str);
free(str);
if(str != NULL)
{
strcpy(str, "world");
printf(str);
}