先看问题,下面只我最近刷题发现的几个高频题
char *GetMemory(void)
{
char p[] = "hello world";
printf("%s\n", p);
return p;
}
void GetMemory1(char *p)
{
p = (char *)malloc(100);
}
void GetMemory2(char *&p, int num)
{
p = (char *)malloc(num);
}
void Test(void)
{
char*str = NULL;
printf("%x\n", str);
str = (char *)malloc(100);
printf("%x\n", str);
//str = NULL;
strcpy(str, "hello");
printf("%x\n", str);
free(str);
printf("%x\n", str);
if (str != NULL)
{
strcpy(str, "word");
printf("%s\n",str);
}
}