网上收集的C++笔试题目(2)

原创 2010年06月10日 13:15:00

说明:下划线是我认为的答案,仅供参考。

【Q1】 Which of the following statements describe the results of executing the code snippet below in C++?

int var = 1;

void main()

{

int i = i;

}

 

A.    The i within main will have an undefined value.

B.    The compiler will allow this statement, but the linker will not be able to resolve the declaration of i.

C.    The i within main will have a value of 1.

D.    The compiler will not allow this statement.

E.    The result is compiler-dependent.

 

【Q2】 Which of the following methods can a developer use to override the default terminate() function in C++?

A.    Write the terminate() function with two int arguments.

B.    Write the terminate() function with a runtime_error argument.

C.    Pass the address of the overriding function to the set_terminate() function.

D.    Write the terminate() function with one int argument.

E.    Write the terminate() function with a runtime_exception argument.

 

【Q3】 Which of the following are not pre-processor directives in C++?

A.    #ifndef

B.    #ifdef

C.    #elif

D.    #define

E.    #extern

 

【Q4】 Which allocator member function do standard containers use to acquire storage for their elements in C++?

A.    std::allocator<>::allocate(size_t)

B.    std::allocator<>::malloc(int)

C.    std::allocator<>::make(size_t)

D.    std::allocator<>::new(size_t)

E.    std::allocator<>::acquire(size_t)

 

【Q5】 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 does not have standardized run-time behavior.

B.    RTTI uses too much memory.

C.    RTTI is too slow.

D.    RTTI's performance is unpredictable/non-deterministic.

E.    RTTI frequently fails to function correctly at run-time.

 

【Q6】 Which of the following functions of the ifstream class can be used to determine the current position of the stream's get pointer in C++?

A.    void tellg(pos_type&)

B.    pos_type tellg()

C.    pos_type tellp()

D.    void tellp(pos_type&)

E.    void seekg(pos_type&)

 

【Q7】 Which of the following C++ keywords are designed to speed up execution of a C++ function?

A.    friend

B.    static

C.    extern

D.    inline

E.    member

 

【Q8】 Which of the following template declarations provide the correct syntax to write a template class

template <class T> class Derived;

that has to inherit from another template class

template <class T> class Base;

 

A.    template <class T, class Q> class Derived<Q> : public Base<T>

where Q can be used as the templatized type for class Derived.

B.    template <class T, class Q> class Derived : public Base

where Q can be used as the templatized type for class Derived.

C.    template <class T, class Q> class Derived : public Base<T>

where Q can be used as the templatized type for class Derived.

D.    template <class T, class Q> class Derived<Q> : public Base

where Q can be used as the templatized type for class Derived.

E.    template <class Q> class Derived<Q> : public Base

 

【Q9】 Which of the following options describe the expected overhead for a class that has 5 virtual functions?

A.    Every object of the class holds the address of a structure holding the addresses of the 5 virtual functions.

B.    Every object of the class holds the addresses of the 5 virtual functions.

C.    Every object of the class holds the address of the first virtual function, and each function in turn holds the address of the next virtual function.

D.    Every object of the class holds the address of a link list object that holds the addresses of the virtual functions.

E.    Every object of the class holds the address of the class declaration in memory, through which the virtual function calls are resolved.

 

【Q10】 Which of the following reasons describe why a destructor cannot throw an exception in C++?

A.    It can invoke the terminate() handler.

B.    Since the object is being destroyed, it is illogical to throw an exception then.

C.    The C++ language does not permit it; a throw statement in a destructor will be caught as an error by the compiler.

D.    A destructor may be invoked as a result of stack unwinding while an exception is being handled.

E.    A destructor in C++ cannot implement a try...catch block.

 

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

网上收集的C++笔试题目(7)

说明:下划线是我认为的答案,仅供参考。【Q1】 Which of the following must be ensured in order to implement a polymorphic f...
  • donhao
  • donhao
  • 2010年06月11日 08:33
  • 5886

网上收集的C++笔试题目(1)

说明:下划线是我认为的答案,仅供参考。【Q1】 Which of the following statements accurately describe unary operator overloa...
  • donhao
  • donhao
  • 2010年06月10日 13:15
  • 8337

C/C++ 笔试、面试题目大汇总2

见上一篇:C/C++ 笔试、面试题目大汇总 继续 ~~~~~~~~~ 一.找错题 试题1: void test1() {  char string[10];  char* str1 ...

C++笔试面试题 从网上整理的,带答案

1.new 、 delete 、 malloc 、 free 关系 delete 会调用对象的析构函数 , 和 new 对应 free 只会释放内存, new 调用构造函数。 malloc 与 fr...

今天在网上看到一个百度的C++面试题目

将一个含有正数和负数的数组按负数在前正数在后的顺序排列,负数与负数间,正数与正数间的相对位置不变。 刚看到这个题目,感觉和之前学过的所有排序都不一样,仔细想其实就是个插入排序的变形。 例如数组[-...

C++笔试题目

  • 2013年10月01日 18:25
  • 914KB
  • 下载

最新爱立信c++笔试题目

  • 2009年10月15日 16:28
  • 519B
  • 下载

经典C++笔试题目--100(编程练习(比C要难)(91-100))

编程练习(比C要难)(91-100) 91、请编写一个 C 函数,该函数给出一个字节中被置 1 的位的个数。  【参考答案】 unsigned int TestAsOne0(char...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:网上收集的C++笔试题目(2)
举报原因:
原因补充:

(最多只允许输入30个字)