其他公司的笔试题7
来源:互联网 发布:linux ftp配置文件丢失 编辑:程序博客网 时间:2024/04/30 13:01
int a,b,c 请写函数实现C=a+b ,不可以改变数据类型,如将c改为long int,关键是如何处理溢出问题
bool add (int a, int b,int *c)
{
*c=a+b;
return (a>0 && b>0 &&(*c<a || *c<b) || (a<0 && b<0 &&(*c>a || *c>b));
}
溢出返回1
1-- 简述操作系统内存管理方式和区别
段式,页式,段页式。区别:段式,内存分为若干大小不等的段;页式,内存分为大小等同的页;段页式,先分段,段内再分成若干页。 区别,,是否产生碎片?
2--- 什么是死锁,什么是饿死
死锁是系统处于的某种状态,这种状态下,所有处于死锁进程都处于”等待态“,并且循环等待别的进程的资源。饿死是指某一(些)进程永远得不到所期望的资源。
3--- 什么叫IPC,有几种方式?
桌面上有三个盒子,其中一个里面有手机,而另外两个是空的.主持人首先让你选择一个,然后她去打开剩下的一个空的盒子,然后他问你要不要和最后剩下的那个盒子交换,请写个程序证明是换好还是不换好!
换好
这个是玛丽莲小姐问题。答案是换。
当主持人去掉一个错误答案后,
如果不换,那么开始选对就选对了,没选对就没选对,主持人的行为对你没有任何影响,所以选对的概率是1/3。
如果换,那么如果开始选对,现在就错了,如果开始选错,现在就对了。也就是说,如果开始选错了,那么结果就能选对。因为空盒子有2个,选错的概率是2/3,也就是说,最后选对的概率是2/3。
所以答案是换。
void main()
{
int i,b,c,j;
int a[3];
int change=0;
int nochange=0;
for(i=0;i<10000;i++)
{
a[0]=0;
a[1]=0;
a[2]=0;
a[int(rand()%3)]=1; //一个手机
b=int(rand()%3); //选择的一个
while(1)
{
c=int(rand()%3);
if(c!=b&&a[c]==0) //主持人打开一个空的
break;
}
if(a[b]==1) nochange++; //不换
else change++;
}
printf("change:%d/n",change);
printf("nochange:%d/n",nochange);
}
结果为:
change:6613
nochange:3387
假如把网络40.15.0.0分成两个子网,第一个是40.15.0.0/17,那么第二个子网将是: d
a. 40.15.1.0/17
b. 40.15.2.0/16
c. 40.15.100.0/17
d. 40.15.128.0/17
17表示转换为二进制时前17位为子网号,在第前17位加1,也就是点分10进制第三部分加上1000 0000 也就是128
中软面最后一道面试题
class ABase
{
public:
ABase():Aval(10) { cout<<"construct ABase!"<<endl; }
~ABase() { cout<<"destory ABase!"<<endl; }
protected:
int Aval;
};
class CBase
{
public:
CBase(ABase &at):a(at)
{
cout<<"construct CBase!"<<endl;
}
~CBase()
{
cout<<"destory CBase!"<<endl;
}
private:
int Cval;
ABase a;
};
int main()
{
ABase aa;
CBase bb(aa);
return 0;
}
输出结果是什么?为什么?
如果把类CBase的构造函数改成如下:
CBase(ABase &at)
{
a = at;
cout<<"construct CBase!"<<endl;
}
输出结果是什么?并说明原因?
construct ABase!
construct CBase!
destroy CBase!
destroy ABase!
destroy ABase!
然后改成a = at;结果是:
construct ABase!
construct ABase!
construct CBase!
destroy CBase!
destroy ABase!
destroy Abase!
CBase(ABase &at):a(at)
{
。。。
}
指明了调用a的copy constructor
CBase(ABase &at)
{
a = at;
cout<<"construct CBase!"<<endl;
}
构造函数等效于
CBase(ABase &at) : a()
{
a = at;
cout<<"construct CBase!"<<endl;
}
5*(5-1/5)=5*4.8=24
1。const,volatile,makefile的作用是什么?
是防止编译器把数据优化入cache,比如我们要访问的某个地址其实是个外设端口,如果优化入cahce,那么每次访问就不一定能得到预期的值
2。使用函数指针数组替代switch语句
原始代码示例:
enum NodeType {NodeA,NodeB,NodeC};
switch(getNodeType())
{
case NodeA:
...
...
case NodeB:
...
...
case NodeC:
...
...
}
更改后的代码示例(请填写):
int processNodeA(void);
int processNodeB(void);
int processNodeC(void);
/*Establishment of a table of points to functions*/
int (*p[3])(void);
p[NodeA] = processNodeA;
p[NodeB] = processNodeB;
p[NodeC] = processNodeC;
//execute the function
p[getNodeType()]();
/*The entire switch statement is replaced by next line*/
3。please implements follow functions
LISTNODE and TREENODE are two data types that you are going to used in answering some of the questions.These two data types are defined as follows:
struct listNode{
char data;
struct listNode * next;
};
typedef LISTNODE struct listNode;
struct treeNode{
char data;
struct treeNode * left;
struct treeNode * right;
};
typedef TREENODE struct treeNode;
1) write a recursive function that returns the depth of a given node. note that a terminal node should have a depth of zero.The prototype of the desired function looks like this:
int treeDepth (TREENODE * root);
递归得出树的高度,空树高度为0;
int treeDepth (TREENODE * root)
{
int nDepth = 0;
if (NULL != root)
{
int nDepthLeft = treeDepth(root->left);
int nDepthRight = treeDepth(root->right);
nDepth = nDepthLeft > nDepthRight ? nDepthLeft : nDepthRight;
nDepth++;
}
return nDepth;
}
2)A set can be implemented as a linked list. write a function that returns a new list that represents the union of two given lists. Note that:
2.1) Since the list represents a set ,there is no special ordering and no duplicated items in the given and returned lists.
2.2) The function should not change either of the given lists.
链表合并,没有重复项,无序,不能改变原来的链表
先对各自链表排序,然后合并?这样空间复杂度高
1。C++的类型转换有几种?
2。标准C++的动态类型识别信息是什么类?
type_info
3。MFC支持那些异常处理,举几个例子
4。如果一个包容器包含指向对象的指针,当从该包容器中删除某个指针时,会析构该指针指向的对象吗?
不
5。请说明哪些运算符必须是类的成员变量?
6。如何阻止构造函数的自动转换。
Explicit
7。说明一下两个程序的区别
1.
#include <stdio>
struct tt {
char t1;
long t2;
};
void main()
{
printf("%d/n", sizeof(struct tt));
}
2.
#pragma pack(1)
#include <stdio>
struct tt {
char t1;
long t2;
};
void main()
{
printf("%d/n", sizeof(struct tt));
}
8和5
8。说明抽象基类的功能
9。如果要求一个类Singleton中只可以有一个实例,如何实现?
头文件中的声明部分:
class Singleton
{
public:
static Singleton* Instance();
protected:
Singleton();
private:
static Singleton* _instance;
}
实现部分的实现:
10。已知一结构名为struct aaa, member是其一个数据成员。请问如何在不定义任何该结构变量的情况下,取得member在struct aaa内的偏移量(单位:字节)?
今天NEC笔试的题,请各位高手教我
题目:
以下是求“斐波纳契数列:1,1,2,3,5,8,13,21..."用循环实现的函数,后一函数将程序精简(也用循环实现)
请在划线处填空,每空只能填一个语句
原函数:
int fib2(int n) /*n表示求斐波纳契数列的第n个数*/
{
int a=1,b=1,c=0,k;
if(n==0) return 0;
else
{
if(n==1||n==2) return 1;
for(k=2;k<n;k++)
{
c=b;b=a+b;a=c;
i++; /*说明,此处i用于记录循环的次数 */
}
}
return b;
}
精简函数:
int fib2(int n)
{
int a=1,b=1,c=0,k;
if(n==0) return 0;
if(n==1||n==2) return 1; ________________; /*第一个空*/
for(k=2;k<n;k++)
{
b=(c=b)+a; ______________; /*第二个空*/
a=c;
}
return b;
}
请各位高手作答,我实在弄不明白,想请教
- 其他公司的笔试题7
- 其他公司的笔试题1
- 其他公司的笔试题2
- 其他公司的笔试题3
- 其他公司的笔试题4
- 其他公司的笔试题5
- 其他公司的笔试题6
- 其他公司的笔试题8
- 其他公司的笔试题9
- 其他公司的笔试题6
- 一些公司的笔试题
- 一些公司的笔试题
- Trilogy公司的笔试题
- Trilogy公司的笔试题
- 一个游戏公司的笔试题
- 一些公司的笔试题【史上最全】
- 一些公司的电子类笔试题
- 一些公司的电子类笔试题
- 其他公司的笔试题5
- C#中调用Windows API的要点
- 有家的感觉!
- 其他公司的笔试题6
- oracle的应用
- 其他公司的笔试题7
- 其他公司的笔试题8
- C++和VC++学习方法
- 使用 JIRA 搭建企业问题跟踪系统
- 累了 十种放松方式
- 理解逻辑地址(基地址:偏移量)的汇编程序
- javascript连接access数据库
- 其他公司的笔试题9
- 我喜欢的博客风格——CSDN