首页 > 试题广场 >

下面程序的输出结果是( &n...

[单选题]
下面程序的输出结果是(      )
#include <stdio.h>
#include <stdlib.h>
void MallocMem(char* pc)
{
pc = (char*) malloc (100);

return;
}

int main()
{
char *str=NULL;

MallocMem(str);
strcpy(str,"hello ");
strcat(str+2, "world");

printf("%s",str);

return 0;
}
  • hello world
  • 程序编译错误
  • 程序运行时崩溃
  • 其他几项都不对
MallocMem属于指针传递参数,实参str会在函数内部创建副本,对此副本值的修改不会影响实参,即调用函数后实参str依然为NULL。strcpy将"hello "写入str(NULL)时发生错误。
编辑于 2019-08-29 20:14:35 回复(4)