char *GetMemory(void){ char p[] = "hello world";return
p; }void Test(void){char *str = NULL;str = GetMemory(); printf(str);}请问运行 Tes
t 函数会有什么样的结果?
第1题:
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 函数会有什么样的结果?
第2题:
下面的程序各自独立,请问执行下面的四个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);
}
}
第3题:
35、以下程序的运行结果是___________。 void print(char *s){ printf("%s", s); } int main(){ char *p, *q; char str[]="Hello, World\n"; q=p=str; p++; printf(q); printf(p); return 0; }
A.H e
B.Hello, World ello, World
C.Hello, World Hello, World
D.ello, World llo, World
第4题:
void Test(void){char *str = (char *)
malloc(100); strcpy(str, “hello”); free(str); if(str != NULL) { strcpy(str, “
world”); printf(str);}}请问运行 Test 函数会有什么样的结果?
第5题:
分析下面的程序,指出程序中的错误: # include <stdio.h> int main(void) { char a; char *str=&a; strcpy(str,"hello"); printf("%sn",str); return 0; }