首页 > 考试题库
题目内容 (请给出正确答案)
[主观题]

试题4:void GetMemory(char *p ){p = (char *) malloc(100 );}void Test(void ){char *str =

试题4:

void GetMemory(char *p )

{

p = (char *) malloc(100 );

}

void Test(void )

{

char *str = NULL;

GetMemory(str );

strcpy(str, "hello world" );

printf(str );

}

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“试题4:void GetMemory(char *p ){p…”相关的问题
第1题
试题4: void GetMemory(char *p ){ p = (char *) malloc(100 );} void Test(void ) { char *

试题4:

void GetMemory(char *p )

{

p = (char *) malloc(100 );

}

void Test(void )

{

char *str = NULL;

GetMemory(str );

strcpy(str, "hello world" );

printf(str );

}

点击查看答案
第2题
试题6:void GetMemory(char **p, int num ){*p = (char *) malloc(num );}void Test(void ){c

试题6:

void GetMemory(char **p, int num )

{

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

}

void Test(void )

{

char *str = NULL;

GetMemory(&str, 100 );

strcpy(str, "hello" );

printf(str );

点击查看答案
第3题
试题5: char *GetMemory(void ){ char p[] = "hello world"; return p; } void Test(void )

试题5:

char *GetMemory(void )

{

char p[] = "hello world";

return p;

}

void Test(void )

{

char *str = NULL;

str = GetMemory();

printf(str );

}

点击查看答案
第4题
试题5:char *GetMemory(void ){char p[] = "hello world";return p;}void Test(void ){char *s

试题5:

char *GetMemory(void )

{

char p[] = "hello world";

return p;

}

void Test(void )

{

char *str = NULL;

str = GetMemory();

printf(str );

}

点击查看答案
第5题
试题6: void GetMemory(char **p, int num ){ *p = (char *) malloc(num );} void Test(void

试题6:

void GetMemory(char **p, int num )

{

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

}

void Test(void )

{

char *str = NULL;

GetMemory(&str, 100 );

strcpy(str, "hello" );

printf(str );

}

点击查看答案
第6题
请指出下列程序中的错误并且修改void GetMemory(char *p){p=(char *)malloc(100);}void Test(

请指出下列程序中的错误并且修改

void GetMemory(char *p){

p=(char *)malloc(100);

}

void Test(void){

char *str=NULL;

GetMemory=(str);

strcpy(str,"hello world");

printf(str);

}

A:错误--参数的值改变后,不会传回

GetMemory并不能传递动态内存,Test函数中的str

一直都是NULL。

strcpy(str, "hello world");将使程序崩溃。

点击查看答案
第7题
分析下面的程序: void GetMemory(char **p,int num) { *p=(char *)malloc(num); } int main()

分析下面的程序:

void GetMemory(char **p,int num)

{

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

}

int main()

{

char *str=NULL;

GetMemory(&str,100);

strcpy(str,"hello");

free(str);

if(str!=NULL)

{

strcpy(str,"world");

}

printf("\n str is %s",str);

getchar();

}

问输出结果是什么?希望大家能说说原因,先谢谢了

点击查看答案
第8题
. char *GetMemory(void) { char p[] = "hello world"; return p; } void Test

. char *GetMemory(void) { char p[] = "hello world"; return p; } void Test(void) { char *str = NULL; str = GetMemory(); printf(str); } 请问运行Test 函数会有什么样的结果?

点击查看答案
第9题
回答下面的问题(6分) (1).Void GetMemory(char **p, int num) { *p = (char *)mallo

回答下面的问题(6分) (1).Void GetMemory(char **p, int num) { *p = (char *)malloc(num); } void Test(void) { char *str = NULL; GetMemory(&str, 100); strcpy(str, "hello"); printf(str); } 请问运行Test 函数会有什么样的结果?

点击查看答案
第10题
#include <stdio.h> #include <stdlib.h> void getmemory(char *p) { p=(char *)

#include <stdio.h>

#include <stdlib.h>

void getmemory(char *p)

{

p=(char *) malloc(100);

strcpy(p,"hello world");

}

int main()

{

char *str=NULL;

getmemory(str);

printf("%s/n",str);

free(str);

return 0;

}

程序崩溃,getmemory中的malloc 不能返回动态内存, free()对str操作很危险

5.char szstr[10];

strcpy(szstr,"0123456789");

产生什么结果?为什么?

点击查看答案
退出 登录/注册
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改