您的位置:首页 > 其它

每天一道笔试题-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公司笔试题。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: