1. 程式人生 > >網上收集的C++筆試題目(2)

網上收集的C++筆試題目(2)

說明:下劃線是我認為的答案,僅供參考。

【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.