为什么在二阶指针操作完毕之后,数据又会被回收?
void GetMemory(char **p){
(*p)=(char *)malloc(100);
strcpy((*p),"hello world");
}
int main()
{
char *str=NULL;
GetMemory(&str);
printf("%s",str);
return 0;
}
为什么打印str是空呢?
2011-05-25 18:22
2011-05-25 18:46
2011-05-25 19:22
程序代码:#include <stdio.h>
#include<string>
void GetMemory(char **p)
{
(*p)=(char *)malloc(100);
strcpy((*p),"hello world");
}
int main()
{
char *str=NULL;
GetMemory(&str);
printf("%s",str);
return 0;
}
2011-05-25 19:23
2011-05-25 19:28