运行以下几个Test()函数分别会输出什么结果
我想请问下,运行以下几个Test()函数分别会输出什么结果?
/第一段程序段:
void Memory1(char *p)
{
p=(char*) malloc(100);
}
void Test1()
{
char *str=NULL;
Memory1(str);
strcpy(str,"hello world");
cout<<str<<endl;
}
/第二段程序段:
char* Memory2()
{
char p[]="hello world";
return p;
}
void Test2()
{
char *p=NULL;
p=Memory2();
cout<<p<<endl;
}
/第三段程序段:
void Memory3(char **p, int num)
{
*p = (char *)malloc(sizeof(char) * num);
}
void Test3(void)
{
char *str = NULL;
Memory3(&str, 100);
strcpy(str, "hello");
cout<< str << endl;
}
#C++工程师#
