题库 软件开发 题目列表 下列C/C++代码片段中哪段是可以正确执行的?()...
单选题
下列C/C++代码片段中哪段是可以正确执行的?()
注:如果你能在错误的代码上勾画和标注出错误的语句和原因,有额外加分。
A.

A)     voidGetMemory(char *p) {

p = (char*)malloc(100);

}

voidTest(void) {

char *str = NULL;

GetMemory(str);

strcpy(str,"hello world");

printf(“%s”, str);

}

B.

char *GetMemory(void) { 

char p[] ="hello world";

return p;

}

voidTest(void) {

char *str = NULL;

str = GetMemory();  

printf(“%s”, str);

}

C.

voidGetMemory(char **p, int num) {

*p = (char*)malloc(num);

}

void Test(void){

char*str = NULL;

GetMemory(&str,100);

strcpy(str,"hello"); 

printf(“%s”,str);

free(str);

}

D.

 void Test(void) {

    char *str = (char *)malloc(100);

  strcpy(str, “hello”);

  free(str);    

  if(str != NULL) {

   strcpy(str, “world”); 

printf(“%s”,str);

  }

}

题目信息
校招真题
-
正确率
0
评论
19
点击