收藏 分销(赏)

C++外企笔试题.doc

上传人:精**** 文档编号:3635829 上传时间:2024-07-11 格式:DOC 页数:10 大小:37.50KB 下载积分:8 金币
下载 相关 举报
C++外企笔试题.doc_第1页
第1页 / 共10页
C++外企笔试题.doc_第2页
第2页 / 共10页


点击查看更多>>
资源描述
C++外企笔试题 资料仅供参考 VC++开发工程师笔试题 (时间:1小时 满分:100分) 备注:答案请写在答题纸上,请勿在试卷上涂写 一、 选择题(每题1分,共15分) 1、C++语言的跳转语句中,对于break和continue说法正确的是( ) A)break语句只应用与循环体中 B)continue语句只应用于循环体中 C)break是无条件跳转语句,continue不是 D)break和continue的跳转范围不够明确,容易产生问题 2、for(int x=0,y=o;!x&&y<=5;y++)语句执行循环的次数是( ) A)0 B)5 C)6 D)无次数 3、下面有关重载函数的说法中正确的是( ) A)重载函数必须具有不同的返回值类型; B)重载函数形参个数必须不同; C)重载函数必须有不同的形参列表 D)重载函数名能够不同; 4、下列关于构造函数的描述中,错误的是( ) A)构造函数能够设置默认参数; B)构造函数在定义类对象时自动执行 C)构造函数能够是内联函数; D)构造函数不能够重载 5、下面描述中,表示错误的是( ) A)公有继承时基类中的public成员在派生类中仍是public的 B)公有继承是基类中的private成员在派生类中仍是private的 C)公有继承时基类中的protected成员在派生类中仍是protected的 D)私有继承时基类中的public成员在派生类中是private的 二、 填空题(每题3分,共15分) 1. C++编译器给应用程序分配的内存空间包含那四个区域:__________、__________、__________和__________。 2. 产生死锁的四个必要条件是__________、__________、__________和__________。 3. 面向对象程序设计将__________成员和对___________放在一起作为一个不可分割的整体来处理。 4. 在二叉树中,指针p所指结点为叶子结点的条件是______ 。 5. 已知二叉树有50个叶子结点,则该二叉树的总结点数至少是____ __。 三、 程序改错题(共15分) 要求: (1) 把修改后的函数代码重新写在答题纸上。 (2) 调用f2(1)时打印err1,调用f2(2)时,打印error4 1 static int f1(const char *errstr, unsigned int flag) { 2 int copy, index, len; 3 const static char **__err = {“err1”, “err2”, “err3”, “err4”}; 4 5 if(flag & 0x10000) 6 copy = 1; 7 index = (flag & 0x300000) >> 20; 8 9 if(copy) { 10 len = flag & 0xF; 11 errstr = malloc(len); 12 if(errstr = NULL) 13 return -1; 14 strncpy(errstr, __err[index], sizeof(errstr)); 15 } else 16 errstr = __err + index; 17 } 18 19 void f2(int c) { 20 char *err; 21 22 swtch(c) { 23 case 1: 24 if(f1(err, 0x110004) != -1) 25 printf(err); 26 case 2: 27 if(f1(err, 0x30000D) != -1) 28 printf(err); 29 } 30 } 四、 程序输出结果(每题5分,共20分) 1、第一题 #include<iostream> using namespace std; int f(int); int main() { int i; for(i=0;i<5;i++) cout<<f(I)<<""; return 0; } int f(int i) { static int k=1; for(;i>0;i--) k + = i; return k; } 程序输出结果为: 2、第二题 #include <iostream> #include <string.h> using namespace std; class Student{ public: Student(char* pName="no name",int ssId=0) { strncpy(name,pName,40); name[39]='\0'; id = ssId; cout <<"Constructing new student " <<pName <<endl; } Student(Student& s) { cout <<"Constructing copy of " <<s.name <<endl; strcpy(name,"copy of "); strcat(name,s.name); id=s.id; } ~Student() { cout <<"Destructing " <<name <<endl; } protected: char name[40]; int id; }; void fn(Student s) { cout <<"In function fn()\n"; } void main() { Student randy("Randy",1234); cout <<"Calling fn()\n"; fn(randy); cout <<"Returned from fn()\n"; } 程序输出结果为: 3、第三题 #include<iostream> using namespace std; struct sa{char a[2]; short int d; int b; char c[13];}; struct sb{char e; int b; char a[7]; int *p;}; void main() { char *p_char = NULL; int *p_int = NULL; cout<< sizeof(p_char) <<""; cout<< sizeof(p_int) <<""; cout<< sizeof(short int) <<""; cout<< sizeof(sa) <<""; cout<< sizeof(sb) <<""; } 程序输出结果为: 4、第四题 #include <stdio.h> void main() { char *p = NULL; int a = -10; unsigned int b = 7; if((p=malloc(0)) = = NULL) printf("successed"); else printf("failed"); (a+b)>0 ? printf("OK\n"):printf("Bad\n"); } 程序输出结果为: 五、 简答题(每题3分,共15分) 1. 简述VC中Debug和Release的区别?Assert和Verify的区别? 2. 简述char、wchar_t及TCHAR的区别和联系? 3. 简述COM和DLL的区别和联系? 4. 简述new和malloc, delete和free的区别和联系?C++中为什么要引入new和delete ? 5. 试从性能上讨论STL中Vector和List的区别? 六、 编程题(每题10分,共20分) 1. 合并两个有序单链表。要求:(1)写出合并算法的思路 (2)尽量少占用存储空间 (3)合并函数原型为Node * Merge(Node*head1,Node*head2),其中Node链表中的节点: 定义为:typedef struct NODE{ int value; struct NODE * next;}Node; head1为单链表1的头节点指针,head2为单链表2的头结点指针。 2. 设计一个洗牌算法。描述:现有一副扑克牌共54张,每次玩完牌局后,需要重新洗牌,你的任务是设计一个洗牌算法并用C/C++语言来实现它。 要求: (1)写出算法的设计思路以及存放牌的数据结构 (2)要求设计的算法扩展性,比如能够高效率的洗10万张牌。 (3)算法效率越高牌洗的越充分,本题得分越高。
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 通信科技 > 开发语言

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服