欢迎来到天天文库
浏览记录
ID:45886833
大小:118.27 KB
页数:5页
时间:2019-11-19
《中兴c语言笔试题》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、中兴c语言笔试题 一、请填写BOOL,float,指针变量与“零值”比较的if语句(10分) 提示:这里“零值”可以是0,0.0,FALSE或者“空指针”例如int变量n与“零值”比较的if语句为: if(n==0) if(n=0) 以此类推 请写出BOOLflag与“零值”比较的if语句: 请写出floatx与“零值”比较的if语句: 请写出char*p与“零值”比较的if语句: 二、以下为WindowsNT下的32位C++程序请计算sizeof的值(10分) charstr[]=“Hello”;
2、char*p=str; intn=10; 请计算 sizeof(str)= sizeof(p)= sizeof(n)= voidFunc(charstr[100]) { 请计算 sizeof(str)= } void*p=malloc(100); 请计算 sizeof(p)= 三、简答题(25分) 1、头文件中的ifndef/define/endif干什么用? 2、include和include“filename.h”有什么区别? 3、const有什么用途?(请至少
3、说明两种) 4、在C++程序中调用被C编译器编译后的函数为什么要加extern“C”声明? 5、请简述以下两个for循环的优缺点 //第一个 for(i=0;i { if(condition) DoSomething(); else DoOtherthing(); } //第二个 if(condition) { for(i=0;i DoSomething(); } else { for(i=0;i DoOtherthing(); } 优
4、点: 缺点: 优点: 缺点: 四、有关内存的思考题(20分) voidGetMemory(char*p) { p=(char*)malloc(100); } voidTest(void) { char*str=NULL; GetMemory(str); strcpy(str,helloworld); printf(str); } 请问运行Test函数会有什么样的结果? 答: char*GetMemory(void) { charp[]=hellow
5、orld; returnp; } voidTest(void) { char*str=NULL; str=GetMemory(); printf(str); } 请问运行Test函数会有什么样的结果? 答: VoidGetMemory2(char**p,intnum) { *p=(char*)malloc(num); } voidTest(void) { char*str=NULL; GetMemory(str,100); strcpy(str,hell
6、o); printf(str); } 请问运行Test函数会有什么样的结果? 答: voidTest(void) { char*str=(char*)malloc(100); strcpy(str,“hello”); free(str); if(str=NULL) { strcpy(str,“world”); printf(str); } } 请问运行Test函数会有什么样的结果? 答:
此文档下载收益归作者所有