免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12345下一页
最近访问板块 发新帖
查看: 12999 | 回复: 40
打印 上一主题 下一主题

[C++] 几道C++笔试题,不定项选择,请高手解答分析,欢迎讨论。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-06 01:36 |只看该作者 |倒序浏览
这是我最近找工作遇到的C++笔试题目,不定项选择,最多3个正确答案,有蛮多有疑问的,希望发到这里来求大家一起解答和分析。
虽然面试已经过去(还在等结果),但是不懂的还是要搞懂,说不定下次遇到类似的问题。

9. Which of the following statements provide a valid reason NOT to use RTTI for distributed (i.e. networked between different platforms) applications in C++?
A. RTTI is too slow.
B. RTTI does not have standardized run-time behavior.
C. RTTI uses too much memory.
D. RTTI's performance is unpredictable/non-deterministic.
E. RTTI frequently fails to function correctly at run-time

11. A C++ developer wants to handle a static_cast <char*>() operation for the class String shown below. Which of the following options are valid declarations that will accomplish this task?
class String {
public:
  //...
  //declaration goes here
};
A. char* operator char*();
B. operator char*();
C. char* operator();
D. String operator char*();
E. char* operator String();


16. When a Copy Constructor is not written for a class, the C++ compiler generates one. Which of the following statements correctly describe the actions of this compiler-generated Copy Constructor when invoked?
A. The compiler-generated Copy Constructor makes the object being constructed, a reference to the object passed to it as an argument.
B. The compiler-generated Copy Constructor does not do anything by default.
C. The compiler-generated Copy Constructor performs a member-wise copy of the object passed to it as an argument, into the object being constructed.
D. The compiler-generated Copy Constructor tags the object as having been Copy-Constructed by the compiler.
E. The compiler-generated Copy Constructor invokes the assignment operator of the class.

17. Which of the following must be ensured in order to implement a polymorphic function in C++?
A.        There has to be a pointer of the derived class that has implemented the polymorphic function that holds the address of the derived class object.
B.        The function must be declared as virtual in both the base class and in the derived class that overrides the function.
C.        The function must be declared as pure virtual.
D.        There has to be a base class pointer holding the address of a base or derived class object that has implemented the polymorphic function.
E.        The function must be declared as virtual in the base class.

18. Protected, or private, inheritance, as opposed to public inheritance, models which type of relationship in C++?
A.        Can-only-have-one-of
B.        Is-implemented-in-terms-of
C.        Was-a
D.        Has-a
E.        Shares-a-relationship-with

19. Which of the following statements describe correct methods of handling C++ exceptions?
A.        Once an exception is thrown, the compiler unwinds the heap, freeing any memory dynamically allocated within the block from which the exception was thrown.
B.        In a hierarchy of exception classes, the order of handling exceptions can be from the most specific class to the most general class.
C.        Catching an exception by reference is preferable to catching it by value.
D.        If an exception is caught by its address or pointer, it is the responsibility of the thrower to release the memory occupied by the exception.
E.        To write an exception handler, it is essential to know the concrete class of exception to catch.

20. Which of the following statements regarding functions' default arguments in C++ are correct?
A.        Default arguments cannot be of a user-defined type.
B.        Default arguments exist in the global heap and not on the function's stack.
C.        Default arguments cannot be of pointer type.
D.        Default arguments can never precede non-default arguments.
E.        Default arguments are not considered for generating the function's signature.

21. Which of the following classes must be instantiated so that the object can be used both for reading and writing to the same file in C++?
A.        ofstream
B.        stream
C.        ifstream
D.        fstream
E.        iostream

22.  Which of the following reasons describe why a destructor cannot throw an exception in C++?
A.        Since the object is being destroyed, it is illogical to throw an exception then.
B.        A destructor may be invoked as a result of stack unwinding while an exception is being handled.
C.        It can invoke the terminate() handler.
D.        The C++ language does not permit it; a throw statement in a destructor will be caught as an error by the compiler.
E.        A destructor in C++ cannot implement a try...catch block

24. Which of the following identify const-correctness failures in the C++ program below?
template<typename T>
class MyArray
{
public:
&nbsp;&nbsp;&nbsp;&nbsp;MyArray();
&nbsp;&nbsp;&nbsp;&nbsp;MyArray(MyArray& copy);
&nbsp;&nbsp;&nbsp;&nbsp;MyArray& operator=(MyArray& copy);
&nbsp;&nbsp;&nbsp;&nbsp;//...

};

class MyData
{
public:
&nbsp;&nbsp;&nbsp;&nbsp;MyData(MyArray<int>& x, MyArray<int>& y);
&nbsp;&nbsp;&nbsp;&nbsp;//...

&nbsp;&nbsp;&nbsp;&nbsp;const MyArray<int>& x();
&nbsp;&nbsp;&nbsp;&nbsp;const MyArray<int>& y();
};

MyArray<int> read_data(int*, char**);
void make_changes(MyData* edit);

int main(int argc, char* argv[])
{
&nbsp;&nbsp;&nbsp;&nbsp;const MyArray<int> read_x = read_data(&argc, argv);
&nbsp;&nbsp;&nbsp;&nbsp;const MyArray<int> read_y = read_data(&argc, argv);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;MyData user_data(read_x, read_y);
&nbsp;&nbsp;&nbsp;&nbsp;MyData edit_buffer(user_data);
&nbsp;&nbsp;&nbsp;&nbsp;make_changes(&edit_buffer);
}

A.        MyData(MyArray<int>& x, MyArray<int>& y); should be
MyData(const MyArray<int>& x, const MyArray<int>& y);

B.        MyArray(MyArray& copy); should be
MyArray(const MyArray& copy);

C.        MyArray& operator=(MyArray& copy); should be
const MyArray& operator=(const MyArray& copy);

D.        void make_changes(MyData* edit); should be
void make_changes(const MyData* edit);

E.        const MyArray& operator=(const MyArray& copy); should be
const MyArray& operator=(const MyArray& copy) const;

25. Which of the following operators must be overloaded by function objects in the Standard Template Library?
A.        operator +()
B.        operator ==()
C.        operator ++()
D.        operator ()()
E.        operator []()

======================================================

附上我的选择和疑问,欢迎大家指正和讨论:

9. AD (not quite sure)
11. A (What does this question mean?! Can anyone explain it? )
16. AC  (Is A right?! Should it be 'a CONST reference to the object passed to it as an argument')
17. E (not quite sure. Is A or D right too? )
18. A or E. I have no idea at all!!!!
19 C (Is B right too?)
20. only D?
21. ACD (not sure)
22. BC ?
24. only B ?
25. I choose B only. How about other options?

[ 本帖最后由 zyb2000 于 2008-11-6 18:59 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-11-06 08:50 |只看该作者
太长了

论坛徽章:
0
3 [报告]
发表于 2008-11-06 09:10 |只看该作者
lz最好把你不懂的地方拿出来问。这样摆出所有题,恐怕没人会去做吧

论坛徽章:
0
4 [报告]
发表于 2008-11-06 09:24 |只看该作者
嗯,这样子看确实有点累啊。

论坛徽章:
0
5 [报告]
发表于 2008-11-06 18:01 |只看该作者
阿……很多有疑问阿,怎么办呢……

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
6 [报告]
发表于 2008-11-06 18:03 |只看该作者
顶这家公司一下。不管出的题难以怎么样,至少考虑一下应聘者的英语能力。

论坛徽章:
0
7 [报告]
发表于 2008-11-06 18:59 |只看该作者
Mark  哪个公司  应该是家很不错的

论坛徽章:
0
8 [报告]
发表于 2008-11-06 19:00 |只看该作者
编辑了一下,把十分不确定的题目留了下来,应该少很多了吧,大家再看看?

论坛徽章:
0
9 [报告]
发表于 2008-11-06 19:59 |只看该作者
原题出的不错,删了可惜~

论坛徽章:
0
10 [报告]
发表于 2008-11-06 20:04 |只看该作者
通过楼主的贴子了解了RTTI是什么东西,谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP