教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 综合文档 >

C++语言面试宝典(5)

来源:网络收集 时间:2026-02-19
导读: int *p, *q; p=a; q= 则a[q-p]=? 36. 定义 int **a[3][4], 则变量占有的内存空间为:_____ 37. 编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒。如输入2004年12 月 31日23时59分59秒,则输出2005

int *p, *q; p=a; q=&a[2]; 则a[q-p]=? 36.

定义 int **a[3][4], 则变量占有的内存空间为:_____ 37.

编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒。如输入2004年12 月

31日23时59分59秒,则输出2005年1月1日0时0分0秒。

38.写一个函数,判断一个int型的整数是否是2的幂,即是否可以表示成2^X的形式(不可 以

用循环)

我只知道是用递推,大概写了一下,如下: int IsTwoPow(int s) {

if(s==1)return FALSE; s=s>>1;

if(s>1)IsTwoPow(s);

return (s==1)?TRUE:FALSE;//大概是这个意思,但是这一句似乎不该这么返回! }

39 A,B从一堆玻璃球(共100个)里向外拿球,规则如下: (1)A先拿,然后一人一次交替着拿; (2)每次只能拿1个或2个或4个;

(3)谁拿最后一个球,谁就是最后的失败者; 问A,B谁将是失败者?写出你的判断步骤。 40.已知:无序数组,折半查找,各元素值唯一。

函数原型是:Binary_Seach(int array[], int iValue, int iCount)

array是数组,在里面用折半查找的方法找等于iValue的值,找到返回1否则0,iCount是元

素个数

41.统计一个字符串中字符出现的次数

42.100位以上的超大整数的加法(主要考虑数据结构和加法的实现)。 43.对如下电文:\给出Huffman编码。 44.int (* (*f)(int, int))(int)表示什么含义?

45.x=x+1,x+=1,x++,为这三个语句的效率排序。并说明为什么。 46.中缀表达式 A-(B+C/D)*E的后缀形式是什么? 47.struct S1 {

char c; int i;

};

sizeof(S1) = ?

class X{ public: X();

virtual ~X();

void myMemberFunc(); static void myStaticFunc(); virtual void myVirtualFunc(); private: int i;

char * pstr; char a; }

sizeof(X) = ?

48.找出两个字符串中最大子字符串,如\的最大子串为 \

49.有一百个整数,其中有负数,找出连续三个数之和最大的部分. 50.写一程序实现快速排序. 假设数据输入为一文件 快速算法描述如下 Algorithm Partition

Input: sequence a0, ..., an-1 with n elements

Output: permutation of the sequence such that all elements a0, ..., aj are les s

than or equal to all

elements ai, ..., an-1 (i > j) Method:

choose the element in the middle of the sequence as comparison element x let i = 0 and j = n-1 while ij

search the first element ai which is greater than or equal to x search the last element aj which is less than or equal to x if ij

exchange ai and aj let i = i+1 and j = j-1

After partitioning the sequence, Quicksort treats the two parts recursively by

the same procedure.

The recursion ends whenever a part consists of one element only.

51.写一算法检测单向链表中是否存在环(whether there is a loop in a link list),

要求算法复杂度(Algorithm's complexity是O(n)) 并只使用常数空间(space is O(c)).

注意,你只知道一个指向单向链表头的指针。链表的长度是不定的,而且环出现的地方也 是

不定的,环有可能在头,有可能在中间。而且要求是检测, 不能破坏环的结构. 52.设下列函数已经通过了调试

bool Sort_Array(ArrayType * Pinputarray, ArrayType * Poutarray);

该函数在内存中排序,能把字节数最大为100M字节的ArrayType类型的数组排序。其中 ArrayType是一个

预定义的数组类型(细节无关紧要),Pinputarray,Poutarray分别为排序前的指针和排 序

后的指针。

请用c语言的伪码风格设计一个算法,他调用上面给出的函数完成下列从输入到输出的任务 :

输入:排序前的大文件,名称为char * pinoutfilename ,其内容为用分号分隔的 ArrayType类型的数组元素,可装满4个100M字节的数组。 输出:排序后的大文件char * poutoutfilename。 53.用最有效率的方法算出2乘以8等於几? 54.

1.错误的转义字符是 (c ) A.'\\091' B.'\\\\' C.'\\0' D.'\\''

2.若数组名作实参而指针变量作形参,函数调用实参传给形参的是 (d ) A.数组的长度 B.数组第一个元素的值

C.数组所有元素的值 D.数组第一个元素的地址

3.变量的指针含意是指变量的 (b ) A.值 B.地址 C.存储 D.名字

5.某文件中定义的静态全局变量(或称静态外部变量)其作用域是 (d ) A.只限某个函数 B.本文件 C.跨文件 D.不限制作用域 55.

1. 解二次方程:a*x*x+b*x+c

int Quadratic( double a,double b,double c,double& x1,double& x2); 返回值:解的个数

2. 最大公约数

DWORD Divisor( DWORD dwFirst, DWORD dwSecond ); 返回值:最大公约数

3. 根据蒙特卡洛算法计算圆周率

double PI( DOWRD dwCount/*测试次数*/ ); 返回值:PI

4. 无符号整数乘法,乘数为32bit,结果为64bit 提示:32bit整数分解为16bit相乘

void Multiply( DWORD dwFirst, DWORD dwSecond, DWORD& dwHigh, DWORD& dwLower );

5. 链表排序(从小到大) 节点定义为: struct Node{ int nValue;

struct Node* pNext; };

最后一个节点的pNext = NULL. Node* SortChain( Node* pHead ); 返回值:链表头

c/c++面试题集锦 2006-7-7更新 24.Assignment 2: Picture Processing

Use C++, Java, or similar languages or/and any middleware such as EJB and J2EE

to process a picture with a high resolution (3 Mega Pixels for example). Use

some methodologies to degrade the resolution of the picture to make it quicke r

for browsing. Then divide the degraded picture into 9 sectors equally. Click

any of the 9 sectors will result a detailed picture for this sector with the

same resolution as that of the original picture. This assignment is designed

for you to demonstrate your ability to handle pictures.

25.用<<,>>,|,&实现一个WORD(2个字节)的高低位交换!!

26.要开辟P1,P2,P3,P4内存来做缓冲,大小自定,但这四个缓冲的大小要一样,并且是连续的 !

27.有一浮点型数组A,用C语言写一函数实现对浮点数组A进行降序排序,并输出结果,要求要

以数组A作为函数的入口.(建议用冒泡排序法) 28.找错:

#include #include class Base {

private:

char * name; public:

Base(char * className) {

name = new char[strlen(className)]; strcpy(name, className); }

~Base() {

delete name; }

char * copyName() {

char newname [256]; strcpy(newname, name); return newname; }

char * getName() {

return name; }

static void print(Base base) {

printf(\} };

class Subc …… 此处隐藏:2321字,全部文档内容请下载后查看。喜欢就下载吧 ……

C++语言面试宝典(5).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/402904.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)