为什么在二阶指针操作完毕之后,数据又会被回收?
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是空呢?
#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; }