每天一道笔试题-2012年2月27日

问题一:
请问运行Test函数会有什么样的结果?
分组一:
void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str, "hello world");
printf(str);
}
分组二:
char *GetMemory(void)
{
char p[] = "hello world";
return p;
}
void Test(void)
{
char *str = NULL;
str = GetMemory();
printf(str);
}
分组三:
void GetMemory(char **p, int num)
{
*p = (char *)malloc(num);
}
void Test(void)
{
char *str = NULL;
GetMemory(&str, 100);
strcpy(str, "Hello");
printf(str);
}
分组四:
void Test(void)
{
char *str = (char *)malloc(100);
strcpy(str, "hello");
free(str);
if (str != NULL)
{
  stpcpy(str, "world");
  printf(str);
}
}
出处:某IT公司笔试题。
posted @ 2012-02-28 13:54  我的IT技术  阅读(105)  评论(0编辑  收藏  举报