网上收集的C++笔试题目(1)
来源:互联网 发布:程序员转行做什么好 编辑:程序博客网 时间:2024/05/21 17:40
说明:下划线是我认为的答案,仅供参考。
【Q1】 Which of the following statements accurately describe unary operator overloading in C++?
A. A unary operator can be overloaded with one parameter when the operator function is a class member.
B. A unary operator can be overloaded with one parameter when the operator function is free standing function (not a class member).
C. A unary operator can only be overloaded if the operator function is a class member.
D. A unary operator can be overloaded with no parameters when the operator function is a class member.
E. A unary operator can be overloaded with no parameters when the operator function is a free standing function (not a class member).
【Q2】 Which of the following statements correctly describe the code below in C++?
#define language 437 //Line 1
#if language < 400
#undef language //Line 2
#else //Line 3
#define language 850 //Line 4
#ifdef language //Line 5
printf("%d", language); //Line 6
#endif
#endif
A. An error or warning will occur on Line 6 because a macro cannot be used as part of a preprocessor directive.
B. An error or warning will occur on Line 2 because #undef is not a valid preprocessor directive.
C. An error or warning will occur on Line 4 because language has already been defined.
D. If Line 1 is changed to #define language 300, Line 6 will print "850".
E. An error or warning will occur on Line 3 because #else can only be used as the last conditional in the chain.
【Q3】 Which of the following statements regarding the benefits of using template functions over preprocessor #define macros are correct?
A. A preprocessor macro expansion cannot work when user-defined types are passed to it as arguments.
B. Since the preprocessor does the macro expansion and not the compiler, the build process takes a longer period of time.
C. While expanding #define macros, the preprocessor does no type checking on the arguments to the macro.
D. A preprocessor macro expansion incurs a performance overhead at runtime.
E. It is simple to step into a template function code during the debugging process.
【Q4】 Which of the following are container adapters in the STL (Standard Template Library) in C++?
A. list
B. map
C. stack
D. queue
E. deque
【Q5】 Which of the following correctly identify benefits of the getline() member function for cin over the extraction operator in C++?
A. The getline() function by default, accepts whitespace, and returns on seeing the /n character, whereas the extraction operator returns when it encounters any whitespace character.
B. Delimiters indicating end of input can be specified to the getline() function, whereas the extraction operator has no such facility.
C. The getline() function can be overloaded to accept different argument types, whereas the extraction operator cannot be overloaded.
D. The number of bytes to read can be specified to the getline() function, whereas it cannot be done with the extraction operator.
E. The getline() function can be used like a manipulator with cin, whereas the extraction operator cannot be used as a manipulator.
【Q6】 In which of the following scenarios is a Copy Constructor called or invoked?
A. When no conversion function exists for converting the class object to another class object
B. When an existing object is assigned an object of its own class
C. When a function receives as an argument, an object of the class, by value
D. When a function returns an object of the class by value
E. When creating an object and initializing it with an object of its own class
【Q7】 Which of the following statements describe the result when standard new cannot allocate the requested storage in C++? (Note: older compilers may not implement standard behavior).
A. It throws a bad_alloc exception.
B. It returns null.
C. It returns silently with no effect on the expression.
D. It throws an insufficient_memory exception.
E. It logs an error message to the mem_err.log file.
【Q8】 In C++, which of the following is the best declaration for an overloaded operator[] to allow read-only access (and only read-only access) to the data?
template<typename T>
class MyArray
{
//declaration goes here
};
A. T& operator[](size_t i);
B. const T& operator[](size_t i);
C. const T& operator[](size_t i) const;
D. T& operator[](size_t i)const;
E. T& operator[](const size_t i);
【Q9】 Which of the following declarations of function main are standard or standard conforming extensions? (Please note that some compilers accept ill-formed main declarations, these should be considered incorrect).
A. int main()
B. void main(char* argv[], int argc)
C. int main(int argc, char* argv[])
D. void main()
E. int main(int argc, char* argv[], char* arge[])
【Q10】 What is the correct declaration for a file stream insertion operator for a class my_stuff::my_class as indicated in the C++ code snippet below?
#include <fstream>
namespace my_stuff
{
class my_class
{
public:
int i;
};
//Declaration goes here
}//ns my_stuff
A. std::ofstream& operator<<(std::ofstream& ofs, const my_class&);
B. const my_class& operator<<(const my_class&)
C. std::fstream& operator<<(std::fstream& fs, const my_class&)
D. std::ifstream& operator<<(std::ifstream& ifs, const my_class&)
E. void operator<<(const my_class&)
- 网上收集的C++笔试题目(1)
- 网上收集的C++笔试题目(2)
- 网上收集的C++笔试题目(3)
- 网上收集的C++笔试题目(6)
- 网上收集的C++笔试题目(5)
- 网上收集的C++笔试题目(4)
- 网上收集的C++笔试题目(7)
- 网上收集的C++笔试题目(8)
- 有趣的C笔试题目(收集)
- 笔试题目收集(1)
- C#笔试的一些题目(收集)
- 收集的腾讯笔试题目
- 网上收集的C++面试题目
- 网上收集的Android 题目一
- 找工作党收集的PHP笔试题目
- PHP 笔试题目收集
- 笔试题目收集(2)
- 笔试题目收集(3)
- Oracle数据日期格式化
- 8个笑话顿悟8个道理
- Java的前途
- Socket 传输
- 网上收集的C++笔试题目(2)
- 网上收集的C++笔试题目(1)
- 网上收集的C++笔试题目(3)
- 网上收集的C++笔试题目(6)
- 网上收集的C++笔试题目(5)
- 网上收集的C++笔试题目(4)
- IDictionary与IDictionaryEnumerator
- 设计模式---微波炉模拟程序
- ioc
- symbian PDK安装 (开源 开发)