软件外企C++面试题,大家试试看?
1.What is achieved by prefixing the 'static' keyword to a file-level function or file-level variable declaration?
2.Describe the difference between the “IS A” and “HAS A” object relationships. Which is the stronger relationship and why?
3.Java & C# support interfaces directly with the “interface” keyword.
C++ does not have an “interface” keyword.
How do you create an interface in C++?
Where/when is the use of interfaces especially helpful?
4.If a program requires a large number of execution contexts what can be done to minimise thread scheduling overhead?
5. What does it mean to say that a function is reentrant?
What are some of the ways of achieving re-entrancy?
问题点数:20、回复次数:47Top
1 楼hzhxxx(程序方程)回复于 2006-07-25 09:27:45 得分 0
题目倒是不难,就是要使用 E 文回答,还真是。。。。Top
2 楼OneAudollar()回复于 2006-07-25 09:35:57 得分 0
可以用中文回答啊Top
3 楼xadream(披着凉皮的羊)回复于 2006-07-25 09:47:37 得分 0
全都不会 还有很多单词不认识 晕Top
4 楼notruiyi(什么乱七八糟的)回复于 2006-07-25 09:49:37 得分 0
第一个文件级STATIC的变量是全局的,而函数是局部的
第二个继承的强度最大,可以使用父类的PROTECTED内容
第三个C++使用抽象类表示接口,使用借口暴露功能
第四个看不懂
第五个什么函数持久性和可重入,可重入,只要是不含状态持续的都可以'
函数持久没听过Top
5 楼sankt(宠辱不惊,看庭前花开花落;去留无意,望天空云卷云舒.)回复于 2006-07-25 10:00:12 得分 0
3.Java & C# support interfaces directly with the “interface” keyword.
C++ does not have an “interface” keyword.
How do you create an interface in C++?
Where/when is the use of interfaces especially helpful?
//==============
C++没有interface,可以使用虚基类模拟的
For Ex:
class Test
{
public:
virtual void dosth()=0;
virtual void doother()=0;
};
OOD的一般规则是:面向接口编程,而不是面向实现编程
Top
6 楼bisc_sunny(总是当时携手处,游遍芳丛)回复于 2006-07-25 10:21:32 得分 5
1. When we use static on a variable / function in a file, this variable will get accessable only inside this file (this is not a C++ concept but C).
2. Is A can have access to protected but only public inherit. Private inherit is similar to Has A
3. Interface is nothing else than a parent class with every virtual function = 0
4. Too general question... sometimes we could use message queue, use the provider / consumer mode, pay attention to the priorities of threads
5. Different threads may want to have function call to one routine in parallel. Reentrant means function is designed to support this. Use mutex / lock / semaphore / static variable in function to archieve this.
Top
7 楼rand520(々翔)回复于 2006-07-25 10:23:32 得分 0
看不懂Top
8 楼Jedimaster(CRH = 耻辱号)回复于 2006-07-25 11:04:18 得分 5
1 when we use 'static' prefix to a no-class object like int,float, and so on,it will be only on instantce in memory,and file scope
2 'HasA' and 'isA' ?? sorry,i never used HasA,maybe it should be in class,we use this interface to judge whether has the A ?
3 Easy. Please look at the ICE and CORBA,if defined a language to write interface. In fact,the member functions may be considered as the interface,the key is how you organized your desgin pattern
4 (multi thread)? never use "while" loop it will waste lots of cpu time.
5 EASY,static function is retrant
都回答了,还有一些把握
我这样能去么?Top
9 楼guqst(过关斩将)回复于 2006-07-25 11:49:55 得分 0
呵呵Top
10 楼98440622(民工++)回复于 2006-07-25 13:07:15 得分 0
markTop
11 楼wxc2006()回复于 2006-07-25 13:30:09 得分 0
上面没有一个知道什么叫 re-entrancy
re-entrancy 是 c 和 c++普遍支持的
re-entrancy 是指一个程序被中断之后返回
简单的说就是 c/c++支持中断, 例如 ISR
Top
12 楼goodboy1881(积木)(谁都别拦着我在水源升星)回复于 2006-07-25 13:38:56 得分 0
楼上 C/C++ 啥时候支持中断了?
你说的不是系统调用?Top
13 楼wxc2006()回复于 2006-07-25 13:42:17 得分 0
当然支持中断, 不然你怎么做嵌入系统, 我晕了
Top
14 楼universee(吾乃太极语言之父)回复于 2006-07-25 14:21:51 得分 0
markTop
15 楼sakaibam99(神暮都布川)回复于 2006-07-25 14:52:03 得分 0
不小心路過,不留意學習一下。Top
16 楼improgrammer(无忌)回复于 2006-07-25 15:04:16 得分 0
4Top
17 楼cuiweibing()回复于 2006-07-25 15:16:05 得分 0
trackTop
18 楼improgrammer(无忌)回复于 2006-07-25 15:22:24 得分 0
4 Nothing special need to be done. Thread scheduling only switch the CPU status. Memory and other stuff such as GDI handles is allocated to process, so nothing to do with scheduling overhead.
5 A function is reentrant if more than one thread can call it concurrently. To achieve re-entrancy, application programmers can use critical sections, semaphores. System programmers may use interrupt technology to achieve re-entrancy.
Top
19 楼add777()回复于 2006-07-25 15:47:36 得分 0
han yi xiaTop
20 楼SammyLan((基础决定你能走多远)--英语菜才是真的菜)回复于 2006-07-25 16:23:55 得分 5
1.What is achieved by prefixing the 'static' keyword to a file-level function or file-level variable declaration?
字面理解:使用static修饰词使函数和变量具有文件作用域的目的是什么?
减少名字污染,改变变量的存储区和生存期
2.Describe the difference between the “IS A” and “HAS A” object relationships. Which is the stronger relationship and why?
字面理解:stronger应该是指功能更强大
HAS A;IS A在编译期就决定了对象的行为,但是HAS A可以在运行的时候改变"A"所指向的对象,从而可以在运行时改变其行为;HAS A可以有IS A提供的所有特性(至于访问权限,如果需要,可以赋予friend的关系),范例如下
class B
{
public:
virtual int Foo();
};
继承:
class D:public B
{
......
};
组合:
class D
{
B*pB;//在这里B可以指向任何一个D的派生类
};
面向对象的设计原则是优先使用组合.
3.Java & C# support interfaces directly with the “interface” keyword.
C++ does not have an “interface” keyword.
How do you create an interface in C++?
Where/when is the use of interfaces especially helpful?
这个是抽象类,应该没什么异议了
4.If a program requires a large number of execution contexts what can be done to minimise thread scheduling overhead?
队列,COM里面就是对请求队列进行排队来应对"客户端"的请求的
5. What does it mean to say that a function is reentrant?
What are some of the ways of achieving reentrancy?
函数可重入是指无论什么时候,对于输入相同的参数,得到的结果都一致
要使函数可重入,就要避免在函数中使用静态变量,全局变量(在这里是广义的全局变量,包括全局变量,类的静态变量,以及类的数据成员)
Top
21 楼SammyLan((基础决定你能走多远)--英语菜才是真的菜)回复于 2006-07-25 16:24:52 得分 0
E文太菜
理解有误,请勿见怪(=_=)Top
22 楼playmud((猪头流氓)(抵制日货)(热烈庆祝火箭输球))回复于 2006-07-25 17:37:39 得分 0
确实有误Top
23 楼Stefine(CSDN最菜滴猩猩)回复于 2006-07-25 21:29:18 得分 0
呵呵,前面三个还能勉强理解,后面两个完全不懂Top
24 楼beginnerworld(起点)回复于 2006-07-25 21:30:40 得分 0
英文阿,有难度Top
25 楼OOPhaisky(异化$渴望成功~~)回复于 2006-07-25 21:34:19 得分 0
第4题不太肯定Top
26 楼CQZE(Say It Loudly And Proudly - 发颗药)回复于 2006-07-25 22:54:07 得分 0
4.If a program requires a large number of execution contexts what can be done to minimise thread scheduling overhead?
before starting a thread...initialize all the contexts you need ..after thread ending.release themTop
27 楼i_love_pc(杰子)(欢迎加入技术交流QQ群:23640432)回复于 2006-07-26 08:23:50 得分 0
任重道远(词霸的解释是shoulder heavy responsibilities)
从此好好学E文.Top
28 楼Richard_Hong(武昌鱼)回复于 2006-07-26 10:44:21 得分 0
markTop
29 楼steven_chr()回复于 2006-07-26 10:49:39 得分 0
COM里有关于interface的详细内容。用的主要是抽象基类和多态等技术。Top
30 楼ailoveu2(神秘失控)回复于 2006-07-26 12:59:55 得分 0
4.If a program requires a large number of execution contexts what can be done to minimise thread scheduling overhead?
看不懂啊~~Top
31 楼aronzhou()回复于 2006-07-26 13:22:19 得分 0
aTop
32 楼zyyoung(倡导开源)回复于 2006-07-26 14:51:28 得分 0
第四题,怎么解Top
33 楼DraculaW(成爲牛人,然後離開)回复于 2006-07-26 15:27:40 得分 0
4.If a program requires a large number of execution contexts what can be done to minimise thread scheduling overhead?
大概就是说程序执行时有大量的东西要交换进内存 怎样做才能使线程调度的额外消耗最小Top
34 楼ray_zhaoxin(好)回复于 2006-07-26 15:51:17 得分 0
bisc_sunny正解,5的意思是可重入,怎么中断都来了,晕死!Top
35 楼ZHENG017()回复于 2006-07-26 15:53:52 得分 0
大概就是说程序执行时需要在很多线程之间来回切换.(比方说一个thread在睡眠时需要调度另一个线程运行)
多给几个cpu,让它不需要切换.这是懒人(我)的解决办法.Top
36 楼anchor720(菜鸟)回复于 2006-07-26 15:57:37 得分 0
markTop
37 楼xb_parasite(溺水的游鱼)回复于 2006-07-26 19:55:00 得分 5
1.What is achieved by prefixing the 'static' keyword to a file-level function or file-level variable declaration?
By prefixing the 'static' keyword, the function or the variable will limit it's function to file-level.Any other function outside the file could not access
them.This will enhance both the code safty and decrease the chance of naming conflicts.
2.Describe the difference between the “IS A” and “HAS A” object relationships. Which is the stronger relationship and why?
"IS A" means something is belong to something else. EX. red apple IS A apple.
"HAS A" means something is belong to something else. EX. young mother HAS A baby.
"IS A" is a stronger relationship than "HAS A". The former can only access the public member/method,while the later is able to access the public and protect member/method. Moreover,When you choose "HAS A" relation ship,you inherit some class, so you must initilize it before you initilize yourself.And your class will surely be affected by the parent class.
3.Java & C# support interfaces directly with the “interface” keyword.
C++ does not have an “interface” keyword.
How do you create an interface in C++?
Where/when is the use of interfaces especially helpful?
C++ use pure virtual class to emulate a interfaces.
Design pattern suggest interface oriented design. So when some parts have to implemented totally different but need a common interface, use of interfaces will be especially helpful.
4.If a program requires a large number of execution contexts what can be done to minimise thread scheduling overhead?
We can use something like semaphore,message queue, producer/cosummer model etc.
5. What does it mean to say that a function is reentrant?
What are some of the ways of achieving re-entrancy?
Reentrant means one function can be entered by multi-thread at the same time,and each one will not be affected by anyone else.
One commonly used way to achieving re-entrancy mutex lock(critical section) and semaphore .
Top
38 楼wanghi(海海)回复于 2006-07-26 22:34:37 得分 0
mark 有空再看!!Top
39 楼stoneyrh()回复于 2006-07-26 22:37:42 得分 0
很想说几句话,但实在不知道说什么好。Top
40 楼yeyuboy(海绵)回复于 2006-07-27 01:13:53 得分 0
题目不难,不过本人的E文水平真有点臭,都动用金山词霸了.
1,加了static的函数及变量就没有了外部链接,它只会在该文件内被访问,当其它文件也定义了相同的函数时不会导致链接错误.
2,IS A的关系强于Has A。Is A表示的是继承关系,Has A表示的是组合关系。
3,c++中用virtual修饰符来声明一个成员函数是一个接口。通过执有一个接口类引用或指针来操作其派生类(动态绑定)。
4,(题目看得似懂非懂),用高优先线。
5,可重入的函数是指可以同时调用该函数(并发)而不会出问题。
达到可重入可以将函数设计成不修改除传入参数外的其它外部状态。
当需要修改外部状态时,在函数中进行同步。
Top
41 楼dspfirmware(dspfirmware)回复于 2006-07-27 09:26:37 得分 0
1.What is achieved by prefixing the 'static' keyword to a file-level function or file-level variable declaration?
Answer:关键字static加到一个函数或变量前面时,那么这个变量或函数就被局限在它们所在的文件内部,类似与c++中的私有一样.其它文件访问不到它们.
4.If a program requires a large number of execution contexts what can be done to minimise thread scheduling overhead?
Answer:将这些上下文涉及的局部变量设计成数据结构,然后在线程内部定义一个静态的数据结构,在while(1)循环内部使用数据结构指针来访问上面的数据结构实体.
5. What does it mean to say that a function is reentrant?
What are some of the ways of achieving re-entrancy?
Answer:可重入意味着"共享",多任务间任意访问该函数不会造成资源冲突.
a.函数内部避免使用全局变量;
b.即使不得不使用全局变量,可以使用互斥机制来实现可重入;
c.干脆使用开关中断来实现临界区,实现可重入;
http://blog.sina.com.cn/u/1244756857
■ 一道微软亚洲工程院C语言笔试题的解答
■ union的0x3个妙用(II)
■ 一位嵌入式软件高手曲折感人的成长历程
■ C/C 程序设计员应聘常见面试试题深入剖析
■ 看看你的英语“眼力”
■ union的0x3个妙用(I)
■ 视频会议UB内存管理之测试
■ 视频会议UB内存管理源代码ub.c
■ 视频会议UB内存管理源代码ub.h
■ 视频会议UB内存管理原理及实现
■ 视频会议JB抖动缓冲设计
■ 考考你的c语言功底和英语能力
■ 宏的几个绝妙用法
■ 深入浅出sizeof
■ 想成为嵌入式程序员应知道的0x10个基本问题
■ 让我记忆深刻的一篇英文文章
■ 嵌入式英语Top
42 楼tfp(tfp)回复于 2006-07-27 09:42:13 得分 0
5. What does it mean to say that a function is reentrant?
What are some of the ways of achieving re-entrancy?
seem not refer to threadTop
43 楼Akitce()回复于 2006-07-27 13:10:16 得分 0
学习Top
44 楼Ticci(老刀)回复于 2006-07-27 14:42:33 得分 0
4.If a program requires a large number of execution contexts what can be done to minimise thread scheduling overhead?
字面理解:如果一个程序需要执行一大堆东东,那么如何做才能让线程调度开销最少?
(上面各位的回答似乎理解有误啊。)Top
45 楼goodboy1881(积木)(谁都别拦着我在水源升星)回复于 2006-07-27 15:10:10 得分 0
wxc2006()
C/C++标准和系统调用是两个东西,你给我看看C/C++标准里面哪一页写了中断?Top
46 楼gongyuan()回复于 2006-07-27 18:23:18 得分 0
英文太难了,可以用中文吗?Top
47 楼notruiyi(什么乱七八糟的)回复于 2006-07-30 09:04:41 得分 0
第一个题要说明的是STATIC的文件级变量和STATIC的函数的区别Top




