Jul 13, 2011

[ZT]网上收集的C++笔试题目(5)

说明:下划线是我认为的答案,仅供参考。
【Q1】 Which of the following statements correctly describe C preprocessor directives in C++?
A.    The #pragma directive is machine-independent.
B.    Preprocessor directives are processed before macros are expanded.
C.    The #import directive is used to copy code from a library into the program's source code.
D.    Any number of #else directives can be used between an #if and an #endif.
E.    The #include directive is used to identify binary files that will be linked to the program.

【Q2】 In a hierarchy of exception classes in C++, which of the following represent possible orders of catch blocks when a C++ developer wishes to catch exceptions of more than one class from a hierarchy of exception classes?
A.    Classes belonging to the same hierarchy cannot be part of a common set of catch blocks.
B.    The most derived classes must appear first in the catch order, and the parent classes must follow the child classes.
C.    The most derived classes must appear last in the catch order, and the parent classes must precede the child classes.
D.    The order is unimportant as exception handling is built into the language.
E.    Multiple classes can be caught in a single catch clause as multiple arguments.

【Q3】 Which of the following options describe the functions of an overridden terminate() function?
A.    It performs the desired cleanup and shutdown processing, and then throws a termination_exception.
B.    It performs the desired cleanup and shutdown processing, and then returns an error status value to the calling function.
C.    It performs the desired cleanup and shutdown processing, and then calls abort() or exit().
D.    It performs the desired cleanup and shutdown processing, and if it has restored the system to a stable state, it returns a value of "-1" to indicate successful recovery.
E.    It performs the desired cleanup and shutdown processing, and then calls the unexpected() handler.

【Q4】 What is the correct syntax for portable fstream file paths?
(e.g. the string you would pass to std::fstream:open() to open a file.)
A.    "::directory:file.bin"
B.    "C:/Directory/File.bin"
C.    "/directory/file.bin"
D.    "C://Directory//File.bin"
E.    std:fstream file paths are not portable.

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

【Q6】 Which of the following are accurate statements regarding the declaration and definition of an object in a working C++ program?
A.    An object can be declared only once.
B.    An object can be defined multiple times.
C.    If an object is declared and used, it must be defined.
D.    An object can be declared multiple times but can be defined only once.
E.    An object must be defined for each time it is declared.

【Q7】 In C++, the standard fstream class has a member function exceptions that set the exception mask for the stream. Which of the following are valid choices for the mask?
A.    ios::openbit
B.    ios::eofbit
C.    ios::badbit
D.    ios::failbit
E.    ios::retybit

【Q8】 Of the options below, which allocate a buffer of 100 bytes from the heap in C++?
A.    char* buffer = new[100];
B.    unsigned char* buffer = (unsigned char*)malloc(100);
C.    char* buffer = (char*)malloc(100);
D.    unsigned char* buffer = new[100];
E.    byte* buffer = heap(100);

【Q9】 Which of the following statements correctly identify features of overloading the C++ increment operator?
A.    If the increment operators are not overloaded, then the results of any expression using them are undefined, as the compiler uses the default increment operators to evaluate the expression.
B.    The prefix from is declared as
return_type operator++()
and the postfix form as
return_type operator++(int)
C.    If the postfix form is not defined, the prefix form is used by the compiler.
D.    The prefix from is declared as
return_type operator++(int)
and the postfix form as
return_type operator++()
E.    If the increment operators are not overloaded, the compiler generates defaults which do nothing. The state of the object remains unchanged.

【Q10】 Which of the following is a valid function prototype for a C++ function named Display, which received as STL vector object as an argument?
A.    template <class T> void Display(std::vector& obj);
B.    template <class T> void Display<T>(std::vector& obj);
C.    template <class T> void Display(std::vector<T>& obj);
D.    template <class T> void Display<T>(std::vector<T>& obj);
E.    template <class T, class Q> void Display<T>(std::vector<Q>& obj);

No comments:

Post a Comment