运行以下几个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++工程师#
全部评论
出错 输出空 输出hello
点赞 回复 分享
发布于 2017-10-26 20:43

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务