读文网>创业>职场>面试题

腾讯技术类校园招聘笔试试题及答案

一. 单选题(每题4分,15题,共60分)

1.考虑函数原型void hello(int a,int b=7,char* pszC="*"),下面的函数调用钟,属于不合法调用的是:C

A hello(5) B.hello(5,8) C.hello(6,"#") D.hello(0,0,"#")

解析:

(1)不填写参数,参数按默认值;

(2)

2.下面有关重载函数的说法中正确的是:C

A.重载函数必须具有不同的返回值类型 B.重载函数形参个数必须不同

C.重载函数必须有不同的形参列表 D.重载函数名可以不同

解析:

重载:必须同名函数;必须参数表不同(包含参数个数不同;参数类型不同;或参数个数与类型都不同)

3. 分析一下程序的运行结果:C

#include

class CBase

{

public:

CBase(){cout<<”constructing CBase class”<

~CBase(){cout<<”destructing CBase class”<

};

classCSub : public CBase

{

public:

CSub(){cout<<”constructing CSub class”<

~CSub(){cout<<”destructing CSub class”<

};

void main()

{

CSub obj;

}

A. constructing CSub class B. constructing CBase class

constructing CBase class constructing CSub class

destructing CSub class destructing CBase class

destructing CBase class destructing CSub class

C. constructing CBase class

constructing CSub class

destructing CSub class

destructing CBase class

D. constructing CSub class

constructing CBase class

destructing CBase class

destructing CSub class
#p#副标题#e#

解析:

子类对象生成时:先调用父类的构造函数,然后在调用子类的构造函数;析构时相反

4.在一个cpp文件里面,定义了一个static类型的全局变量,下面一个正确的描述是:A

A.只能在该cpp所在的编译模块中使用该变量

B.该变量的值是不可改变的

C.该变量不能在类的成员函数中引用

D.这种变量只能是基本类型(如int,char)不能是C++类型

解析:

Static全局变量和普通全局变量:

针对:一个工程里有多个cpp文件时

相同点:存储方式相同,都是静态存储;

不同点:作用域不同。

普通全局变量---作用域是整个源程序(含有多个源文件),在各个源文件中都有效

Static全局变量----作用域是当前源文件

5.观察下面一段代码:

class ClassA

{

public:

virtual ~ ClassA(){};

virtual void FunctionA(){};

};

class ClassB

{

public:

virtual void FunctionB(){};

};

class ClassC : public ClassA,public ClassB

{

public:

};

ClassC aObject;

ClassA* pA=&aObject;

ClassB* pB=&aObject;

ClassC* pC=&aObject;

关于pA,pB,pC的取值,下面的描述中正确的是:C

A. pA,pB,pC的取值相同 B. pC=pA+pB C. pA和pB不相同 D.pC不等于pA也不等于pB

6. 参照1.5的代码,假设定义了ClassA* pA2,下面正确的代码是:D

A. pA2=static_cast(pB);

B. void* pVoid=static_cast(pB);

pA2=static_cast(pVoid);

C. pA2=pB;

D. pA2=static_cast(static_cast(pB));//将子对象赋值给父对象
#p#副标题#e#

7.参照1.5的代码,下面那一个语句是不安全的:ABC

A. delete pA B. delete pB C. delete pC

删除哪个都有错误,编译是无错误,运行是有错误

8.下列程序的运行结果为:B

#include

void main()

{

int a=2;

int b=++a;

cout<

}

A.0.5 B.0 C0.7 D.0.6666666

9.有如下一段代码:A

defineADD(x,y) x+y

int m=3;

m+=m*ADD(m,m); //展开后为m=m+m*m+m=3+3*3+3

则m的值为:

A.15 B.12 C.18 D.58

10.如下是一个带权的图,图中结点A到结点D的关键路径的长度是:

A.13 B.15 C.28 D.58

11.下面的模板声明中,正确的是:C

A. template//改为template

B. template

C. template

D. template//分号改为逗号

12.在Windows编程中下面的说法正确的是:C

A. 两个窗口,他们的窗口句柄可以是相同的

B. 两个窗口,他们的处理函数可以是相同的——正确

C. 两个窗口,他们的窗口句柄和窗口处理函数都不可以相同.

13.下面哪种情况下,B不能隐式转换为A?B

A. class B:public A{} B. class A:public B{}

C. class B{operator A();} D. class A{A(const B&);}

14.某公司使用包过滤防火墙控制进出公司局域网的数据,在不考虑使用代理服务器的情况下,下面描述错误的是”该防火墙能够( B )”.

A. 使公司员工只能访问Internet上与其业务联系的公司的IP地址.

B. 仅允许HTTP协议通过,不允许其他协议通过,例如TCP/UDP.

C. 使员工不能直接访问FTP服务器端口号为21的FTP地址.

D. 仅允许公司中具有某些特定IP地址的计算机可以访问外部网络

15.数字字符0的ASCII值为48,若有以下程序:

main()

{

char a=’1’,b=’2’;

printf(“%c,”,b++);

printf(“%d”,b-a);

}

程序运行之后的输出结果是:C

A. 3,2 B. 50,2 C. 2,2 D. 2,50
#p#副标题#e#

二. 填空题(共40分)

本程序从正文文件text.in读入一篇英文短文,统计该短文中不同单词和它的出现次数,并按词典编辑顺序将单词及它的出现次数输出到正文文件word.out中.

程序用一棵有序二叉树存储这些单词及其出现的次数,一边读入一边建立.然后中序遍历该二叉树,将遍历经过的二叉树上的节点的内容输出.

程序中的外部函数

int getword(FILE* pFile,char* pszWordBuffer,int nBufferLen);

从与pFile所对应的文件中读取单词置入pszWordBuffer,并返回1;若单词遇文件尾,已无单词可读时,则返回0.

include

include

include

include

defineSOURCE_FILE "text.in"

defineOUTPUT_FILE "word.out"

defineMAX_WORD_LEN 128

typedef struct treenode

{

char szWord[MAX_WORD_LEN];

int nCount;

struct treenode* pLeft;

struct treenode* pRight;

}BNODE;

int getword(FILE* pFile,char* pasWordBuffer,int nBufferLen);

void binary_tree(BNODE** ppNode,char* pszWord)

{

if(ppNode != NULL && pszWord != NULL)

{

BNODE* pCurrentNode = NULL;

BNODE* pMemoNode = NULL;

int nStrCmpRes=0;

____(1)_____;pCurrentNode=*ppNode

while(pCurrentNode)

{

/*寻找插入位置*/

nStrCmpRes = strcmp(pszWord, ___(2)___ );pCurrentNode->nCount

if(!nStrCmpRes)

{

___(3)___; pCurrentNode->nCount++

return;

}

else

{

___(4)___; pMemoNode=pCurrentNode

pCurrentNode = nStrCmpRes>0? pCurrentNode->pRight : pCurrentNode->pLeft;

}

}

}

pCurrent=new BNODE;

if(pCurrentNode != NULL)

{

memset(pCurrentNode,0,sizeof(BNODE));

strncpy(pCurrentNode->szWord,pszWord,MAX_WORD_LEN-1);

pCurrentNode->nCount=1;

}

if(pMemoNode==NULL)

{

___(5)___; *ppNode= pCurrentNode

}

else if(nStrCmpRes>0)

{

pMemoNode->pRight=pCurrentNode;

}

else

{

pMemoNode->pLeft=pCurrentNode;

}

}

void midorder(FILE* pFile,BNODE* pNode)

{

if(___(6)___) return;!pNode||!pFile

midorder(pFile,pNode->pLeft);

fprintf(pFile,"%s %d",pNode->szWord,pNode->nCount);

midorder(pFile,pNode->pRight);

}

void main()

{

FILE* pFile=NULL;

BNODE* pRootNode=NULL;

char szWord[MAX_WORD_LEN]={0};

pFile=fopen(SOURCE_FILE,"r");

if(pFile==NULL)

{

printf("Can't open file %s",SOURCE_FILE);

return;

}

while(getword(pFile,szWord,MAX_WORD_LEN)==1)

{

binary_tree(___(7)___);// pRootNode,szWord

}

fclose(pFile);

pFile=fopen(OUTPUT_FILE,"w");

midorder(pFile,pRootNode);

fclose(pFile);

}
#p#副标题#e#

三. 附加题(每题30分,2题,共60分)

1. 从程序健壮性进行分析,下面的FillUserInfo函数和Main函数分别存在什么问题?

include

include

defineMAX_NAME_LEN 20

struct USERINFO

{

int nAge;

char szName[MAX_NAME_LEN];

};

void FillUserInfo(USERINFO* parUserInfo)

{

stu::cout<<"请输入用户的个数:";

int nCount=0;

std::cin>>nCount;//未判断输入是否合法

for(int i=0;i

{

std::cout<<"请输入年龄:";

std::cin>>parUserInfo[i]->nAge;//未判断输入是否合法

std::string strName;

std::cout<<"请输入姓名:";

std::cin>>strName; //未判断输入是否合法

strcpy(parUserInfo[i].szName,strName.c_str());

}

}

int main(int argc,char* argv[])

{

USERINFO arUserInfos[100]={0};//

FillUserInfo(arUserInfos);

printf("The first name is:");

printf(arUserInfos[0].szName);

printf("");

return 0;

}

相关热搜

相关文章

【面试题】热点

【面试题】最新