注册 登录
编程论坛 C++教室

[求助]看程序写结果

guyanxin 发布于 2007-04-24 18:12, 504 次点击

void GetMemory(char *p)
{
p = (char *)malloc(100);
}

void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str, "hello world");
printf(str);
}
请问运行Test 函数会有什么样的结果?

4 回复
#2
song42007-04-24 20:03
运行错误嘛

很普通的问题
#3
song42007-04-24 20:04
记得我大一上学期课程设计
犯过这个错误 呵呵当时很菜了
#4
dlcdavid2007-04-24 22:50

程序崩溃。

因为GetMemory并不能传递动态内存,

Test函数中的 str一直都是 NULL。

strcpy(str, "hello world");将使程序崩溃。

#5
guyanxin2007-04-25 13:30
谢谢哈.....
1