当前位置:文档之家› c语言面试题目3

c语言面试题目3

本文来自CSDN博客,转载请标明出处:https://www.doczj.com/doc/c63269477.html,/qinde025/archive/2009/10/29/4742795.aspx

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.对如下电文:"CASTCASTSATATATASA"给出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.找出两个字符串中最大子字符串,如"abractyeyt","dgdsaeactyey"的最大子串为"actyet"
49.有一百个整数,其中有负数,找出连续三个数之和最大的部分.
50.写一程序实现快速排序. 假设数据输入为一文件
快速算法描述如下
Algorithm Partition
Input: sequence a0, ..., an-1 with n elements
Output: permutation of the sequence such that all elements a0, ..., aj are less 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 quicker 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("name: %s\n" , https://www.doczj.com/doc/c63269477.html,);
}
};
class Subclass : public Base
{
public:
Subclass(char * className) : Base(className)
{
}
};
int main()
{
Base * pBase = new Subclass("test");
Base::print(*pBase);
printf("name: %s\n", pBase->getName());
printf("new name: %s\n", pBase->copyName());
return 0;
}
NetFetch [2006-07-07 09:22 AM]
c/c++面试题集锦 2006-7-7更新
21.有双向循环链表结点:
typedef struct node
{
int date;
struct node *front,*next;
}_Node;
有两个双向循环链表A,B,知道其头指针为:pHeadA,pHeadB,请写一函数将两上链表中date值相同的结点删除
22.
char * GetStr()
{
char *tmp;
tmp = "123"
return tmp;
}
void main()
{
printf("%s", GetStr());
}
会输出123吗?123创建在堆上还是栈上呢?123的空间是什么时候释放的?
23.
字符指针、浮点数指针、以及函数指针这三种类型的变量哪个占用的内存最大?为什么?
类ClassB从ClassA派生,那么ClassA *a = new ClassB(…); 试问该表达是否合法?为什么?
如果ClassA中定义并实现虚函数int func(void),ClassB中也实现该函数,那么上述变量a->func()将调用哪个类里面的函数?如果int func(void)不是虚函数,情况又如何?为什么?
char **p, a[16][8]; 问:p=a是否会导致程序在以后出现问题?为什么?
如下所述的if else和switch语句哪个的效率高?为什么?
在同一个进程中,一个模块是否可以通过指针操作破坏其它模块的内存,为什么?
应用程序在运行时的内存包括代码区和数据区,其中数据区又包括哪些部分?

相关主题
文本预览
相关文档 最新文档