第一范文网 - 专业文章范例文档资料分享平台

C++面试宝典

来源:用户分享 时间:2025/5/19 8:38:35 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

几道c笔试题(含参考答案) 1.

What is displayed when f() is called given the code: class Number { public: string type;

Number(): type(“void”) { }

explicit Number(short) : type(“short”) { } Number(int) : type(“int”) { } };

void Show(const Number& n) { cout << n.type; } void f() {

short s = 42; Show(s); } a) void b) short c) int

d) None of the above

2. Which is the correct output for the following code double dArray[2] = {4, 8}, *p, *q; p = &dArray[0]; q = p + 1;

cout << q – p << endl; cout << (int)q - (int)p << endl; a) 1 and 8 b) 8 and 4 c) 4 and 8 d) 8 and 1

PDF 文件使用 \试用版本创建 www.fineprint.cn第一个选C;

虽然传入的是short类型,但是short类型的构造函数被生命被explicit,也就是只能显示类型转换,不能使用隐式类型转换。 第二个选A;

第一个是指针加减,按照的是指向地址类型的加减,只跟类型位置有关,q和p指向的数据类型以实际数据类型来算差一个位置,因此是1。而第二个加减是实际指针值得加减,在内存中一个double类型占据8个字节,因此是8

54.Sony笔试题

1.完成下列程序 * *.*. *..*..*.. *...*...*...*... *....*....*....*....*.... *.....*.....*.....*.....*.....*..... *......*......*......*......*......*......*......

*.......*.......*.......*.......*.......*.......*.......*....... #include #define N 8 int main() { int i; int j; int k;

--------------------------------------------------------- | | | | | |

--------------------------------------------------------- return 0; }

PDF 文件使用 \试用版本创建 www.fineprint.cn 2.完成程序,实现对数组的降序排序 #include void sort( ); int main() {

int array[]={45,56,76,234,1,34,23,2,3}; //数字任//意给出 sort( ); return 0; }

void sort( ) {

____________________________________ | | | |

|-----------------------------------------------------| }

3.费波那其数列,1,1,2,3,5……编写程序求第十项。可以用递归,也可以用其 他方法,但要说明你选择的理由。 #include

int Pheponatch(int); int main() {

printf(\ return 0; }

int Pheponatch(int N) {

-------------------------------- | | | |

-------------------------------- }

4.下列程序运行时会崩溃,请找出错误并改正,并且说明原因。 #include #include

PDF 文件使用 \试用版本创建 www.fineprint.cn typedef struct{ TNode* left; TNode* right; int value; } TNode;

TNode* root=NULL; void append(int N); int main() {

append(63); append(45); append(32); append(77); append(96); append(21);

append(17); // Again, 数字任意给出 }

void append(int N) {

TNode* NewNode=(TNode *)malloc(sizeof(TNode)); NewNode->value=N;

if(root==NULL) {

root=NewNode; return; } else {

TNode* temp; temp=root;

while((N>=temp.value && temp.left!=NULL) || (N !=NULL ))

PDF 文件使用 \试用版本创建 www.fineprint.cn {

while(N>=temp.value && temp.left!=NULL) temp=temp.left;

while(N temp=temp.right; }

if(N>=temp.value) temp.left=NewNode; else

temp.right=NewNode; return; } }

────────────────────────────────────────

55请你分别画出OSI的七层网络结构图和TCP/IP的五层结构图。

应用层:为应用程序提供服务

表示层:处理在两个通信系统中交换信息的表示方式

会话层:负责维护两个结点间会话连接的建立、管理和终止,以及数据交换 传输层:向用户提供可靠的端到端服务。UDP TCP协议。

网络层:通过路由选择算法为分组通过通信子网选择最适当的路径,以及实现拥塞控制、网络互联等功能。数据传输单元是分组。IP地址,路由器,IP协议。

数据链路层:在物理层提供的服务基础上,数据链路层在通信的实体间建立数据链路连接,传输一帧为单位的数据包(,并采用差错控制与流量控制方法,使有差错的物理线路变成无差错的数据链路。)

物理层:传输比特流。传输单元是比特。调制解调器。

PDF 文件使用 \试用版本创建 www.fineprint.cn

搜索更多关于: C++面试宝典 的文档
C++面试宝典.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c3lqiy3zri29s4tl8l1e7_8.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top