问题一:
请问运行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公司笔试题。

相关文章:

  • 2021-09-02
  • 2021-12-02
  • 2021-06-15
  • 2021-06-24
  • 2021-09-20
  • 2022-12-23
  • 2021-11-11
  • 2021-06-22
猜你喜欢
  • 2021-07-02
  • 2021-10-13
  • 2021-06-04
  • 2021-12-25
  • 2021-09-30
  • 2021-11-13
  • 2022-01-24
相关资源
相似解决方案