热门

最新

红包

立Flag

投票

同城

我的

发布
2301_79465388
水墨不写bug
3 年前
true2301_79465388

《C:动态内存规划》笔试题挑战:

题目1:

void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str, "hello world");
printf(str);
}

题目2:
char *GetMemory(void)
{
char p[] = "hello world";
return p;
}
void Test(void)
{
char *str = NULL;
str = GetMemory();
printf(str);
}

题目3:
void GetMemory(char **p, int num)
{
*p = (char *)malloc(num);
}
void Test(void)
{
char *str = NULL;
GetMemory(&str, 100);
strcpy(str, "hello");
printf(str);
}

题目4:
void Test(void)
{
char *str = (char *) malloc(100);
strcpy(str, "hello");
free(str);
if(str != NULL)
{
strcpy(str, "world");
printf(str);
}
}

以上四段代码有什么问题,会造成什么后果,欢迎留言~

答案即将发布~~

CSDN App 扫码分享
分享
2
1
打赏
  • 复制链接
  • 举报
下一条:
笨蛋求救,求大佬帮忙做一下期末作业
立即登录