目前本站已有 十几万 份求职资料啦!


笔试题(Test函数)

10-16 00:00:09 来源:http://www.qz26.com 笔试题目   阅读:8486
导读:void GetMemory(char *p){p = (char *)malloc(100);}void Test(void){char *str = NULL;GetMemory(str);strcpy(str, "hello world");printf(str);}请问运行Test函数会有什么样的结果?答:试题传入GetMemory( char *p )函数的形参为字符串指针,在函数内部修改形参并不能真正的改变传入形参的值,执行完 char *str = NULL; GetMemory( str ); 后的str仍然为NULL;char *GetMemory(void){char p[] = "hello world";return p;}void Test(void){char *str = NULL;str = GetMemory();printf(str);}请问运行Test函数会有什么样的结果?答:可能是乱码。 char p[] = "hel
笔试题(Test函数),标签:银行笔试题目,企业笔试题目,http://www.qz26.com

void GetMemory(char *p)

{

p = (char *)malloc(100);

}

void Test(void)

{

char *str = NULL;

GetMemory(str);

strcpy(str, "hello world");

printf(str);

}

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

答:试题传入GetMemory( char *p )函数的形参为字符串指针,在函数内部修改形参并不能真正的改变传入形参的值,执行完 char *str = NULL; GetMemory( str ); 后的str仍然为NULL;

char *GetMemory(void)

{

char p[] = "hello world";

return p;

}

void Test(void)

{

char *str = NULL;

str = GetMemory();

printf(str);

}

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

答:可能是乱码。 char p[] = "hello world";

      return p; 
的p[]数组为函数内的局部自动变量,在函数返回后,内存已经被释放。这是许多程序员常犯的错误,其根源在于不理解变量的生存期。
 


Tag:笔试题目银行笔试题目,企业笔试题目求职笔试面试 - 笔试题目
【字号: 】 【打印】 【关闭
最新更新
推荐热门
联系我们 | 网站地图 | 财务资料 | 范文大全 | 求职简历 | 财会考试 | 成功励志
Copyright 二六求职资料网 All Right Reserved.
1 2 3 4 5 6 7 8 9 10