下面的程序各自独立,请问执行下面的四个TestMemory 函数各有什么样的结果?①void GetMemory(char

题目

下面的程序各自独立,请问执行下面的四个TestMemory 函数各有什么样的结果?

①void GetMemory(char * p)

{

p = (char * )malloc(100);

}

void TestMemory (void)

{

char *str = NULL;

GetMemory (str);

strcpy(str, "hello world");

prinff(str);

}

② char * GetMemory (void)

{

char p[ ] = "hello world";

return p;

}

void TestMemory (void)

{

char * str = NULL;

str = GetMemory( );

printf(str);

}

③void GetMemory(char * * p, int num)

{

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

}

void TestMemory (void)

{

char * str = NULL;

GetMemory(&str, 100);

strcpy( str, "hello" );

printf(sir);

}

④void TestMemory (void)

{

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

strepy (str, "hello" );

free ( str );

if(str ! = NULL)

{

strepy( str, "world" );

printf(str);

}

}

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

分析下面的程序,指出程序中的错误: # include <stdio.h> int main(void) { char a; char *str=&a; strcpy(str,"hello"); printf("%sn",str); return 0; }


342错了,字节数据最大是255

第2题:

当执行下.面的程序时,其输出结果为 ______。 union st { int a; char b; } main() { union st s; char* p=(char *)&s; s.a=0x3132; s.b=0x33; printf("%c",*p); }

A.1

B.2

C.3

D.不确定


正确答案:C
解析:共用体类型结构的特点是使几个不同的变量共占同一段内存,但在每一瞬时只能存放其中一种,而不是同时存放几种,共用体变量中起作用的成员是最后一次存放的成员,在存入一个新的成员后原有的成员就失去作用。因此本题起作用的是成员b的值,所以程序打印输出3。

第3题:

void Test(void){char *str = (char *)

malloc(100); strcpy(str, “hello”); free(str); if(str != NULL) { strcpy(str, “

world”); printf(str);}}请问运行 Test 函数会有什么样的结果?


正确答案:
 

第4题:

Void GetMemory2(char **p, int num){*p = (char *)malloc(num);}void

Test(void){char *str = NULL;GetMemory(&str, 100);strcpy(str, "hello"); printf(str); }请问

运行Test 函数会有什么样的结果?


正确答案:
 

第5题:

char *GetMemory(void){ char p[] = "hello world";return

p; }void Test(void){char *str = NULL;str = GetMemory(); printf(str);}请问运行 Tes

t 函数会有什么样的结果?


正确答案:
 

第6题:

void GetMemory(char *p){p = (char *)malloc(100);}void Test(void) {char *str

= NULL;GetMemory(str); strcpy(str, "hello world");printf(str);}请问运行 Test 函数

会有什么样的结果?


正确答案:
 

第7题:

char*getmemory(void)

{ char p[]=”hello world”;

return p;

}

void test(void)

{

char *str=null;

str=Getmemory();

printf(str);

} 请问运行 Test 函数会有什么样的结果.


正确答案:
 

第8题:

有关内存的思考题

1. void getmemory(char *p)

{ p=(char*)mallol(100);

}

void test(void)

{

char * str =null;

getmemory(str);

strcpy(str,”hello,world”);

printf(str);

}

请问运行 Test 函数会有什么样的结果


正确答案:
 

第9题:

void setmemory(char **p, int num)

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

void test(void)

{ char *str=NULL;

getmemory(&str,100);

strcpy(str,"hello");

printf(str);

}

运行test函数有什么结果?( )


正确答案: