每天一道笔试题-2012年2月27日
2012-02-28 13:54
225 查看
问题一:
请问运行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公司笔试题。
请问运行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公司笔试题。
相关文章推荐
- 每天一道笔试题-2012年2月27日
- 每天一道笔试题-2012年2月20日
- 每天一道笔试题-2012年3月5日
- 每天一道笔试题-2012年3月12日
- 每天一道C++笔试题 II
- 每天一道笔试题-2012年2月20日
- 每天一道笔试题-2012年2月21日
- 每天一道笔试题-2012年2月24日
- 每天一道笔试题-2012年3月1日
- 每天一道笔试题-2012年2月22日
- 每天一道笔试题-2012年3月1日
- 每天一道笔试题-2012年2月22日
- 每天一道笔试题-2012年2月24日
- 每天一道笔试题-2012年2月28日
- 每天一道笔试题-2012年2月28日
- 每天一道C++笔试题 III --- strcmp
- 每天一道笔试题-2012年2月17日
- 每天一道笔试题-2012年2月16日
- 每天一道笔试题(腾讯1)
- 每天一道笔试题-2012年2月16日