#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.
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.
C E
B. map
C. stack
D. queue
E. deque
顺序性容器 | |
vector | 从后面快速的插入与删除,直接访问任何元素 |
deque | 从前面或后面快速的插入与删除,直接访问任何元素 |
list | 双链表,从任何地方快速插入与删除 |
关联容器 | |
set | 快速查找,不允许重复值 |
multiset | 快速查找,允许重复值 |
map | 一对多映射,基于关键字快速查找,不允许重复值 |
multimap | 一对多映射,基于关键字快速查找,允许重复值 |
容器适配器 | |
stack | 后进先出 |
queue | 先进先出 |
priority_queue | 最高优先级元素总是第一个出列 |
C D
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.
A B D
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
C D E
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
A
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);
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.
C
A. #ifndef
B. #ifdef
C. #elif
D. #define
E. #extern
E
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)
A
A. void tellg(pos_type&)
B. pos_type tellg()
C. pos_type tellp()
D. void tellp(pos_type&)
E. void seekg(pos_type&)
BC
获得和设置流指针(get and put stream pointers)
所有输入/输出流对象(i/o streams objects)都有至少一个流指针:
- ifstream, 类似istream, 有一个被称为get pointer的指针,指向下一个将被读取的元素。
- ofstream, 类似 ostream, 有一个指针 put pointer ,指向写入下一个元素的位置。
- fstream, 类似 iostream, 同时继承了get 和 put
我们可以通过使用以下成员函数来读出或配置这些指向流中读写位置的流指针:
-
tellg() 和 tellp()
这两个成员函数不用传入参数,返回pos_type 类型的值(根据ANSI-C++ 标准) ,就是一个整数,代表当前get 流指针的位置 (用tellg) 或 put 流指针的位置(用tellp).
-
seekg() 和seekp()
这对函数分别用来改变流指针get 和put的位置。两个函数都被重载为两种不同的原型:
seekg ( pos_type position );
seekp ( pos_type position );使用这个原型,流指针被改变为指向从文件开始计算的一个绝对位置。要求传入的参数类型与函数 tellg 和tellp 的返回值类型相同。
seekg ( off_type offset, seekdir direction );
seekp ( off_type offset, seekdir direction );使用这个原型可以指定由参数direction决定的一个具体的指针开始计算的一个位移(offset)。它可以是:
ios::beg 从流开始位置计算的位移 ios::cur 从流指针当前位置开始计算的位移 ios::end 从流末尾处开始计算的位移
流指针 get 和 put 的值对文本文件(text file)和二进制文件(binary file)的计算方法都是不同的,因为文本模式的文件中某些特殊字符可能被修改。由于这个原因,建议对以文本文件模式打开的文件总是使用seekg 和 seekp的第一种原型,而且不要对tellg 或 tellp 的返回值进行修改。对二进制文件,你可以任意使用这些函数,应该不会有任何意外的行为产生。
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
C
1. 模版类申明和定义要写在一起
2. template <class T>
class Derived : public Base<T>
{
};
也是正确的
- class Base
- {
- public:
- Base(){cout << "In Base Ctor/n";
- }
- class Nest
- {
- public:
- Nest(){cout << "In Nest Ctor/n"; }
- };
- };
- class Derive : public Base
- {
- public:
- Derive(){cout << "In Derive Ctor/n"; }
- };
- void main()
- {
- Derive obj;
- }
A. Base constructor
Derive constructor
B. Base constructor
Derive constructor
Nest constructor
C. Base constructor
Nest constructor
Derive constructor
D. Nest constructor
Base constructor
Derive constructor
E. Derive constructor
Base constructor
Nest constructor
A
嵌套类是独立的类,基本上与它们的外围类不相关,因此,外围类和嵌套类的对象是互相独立的。嵌套类型的对象不具备外围类所定义的成员,同样,外围类的成员也不具备嵌套类所定义的成员。
嵌套类的名字在其外围类的作用域中可见,但在其他类作用域或定义外围类的作用域中不可见。嵌套类的名字将不会与另一作用域中声明的名字冲突。
嵌套类可以具有与非嵌套类相同种类的成员。像任何其他类一样,嵌套类使用访问标号控制对自己成员的访问。成员可以声明为 public、 private 或 protected。外围类对嵌套类的成员没有特殊访问权,并且嵌套类对其外围类的成员也没有特殊访问权。
嵌套类定义了其外围类中的一个类型成员。像任何其他成员一样,外围类决定对这个类型的访问。在外围类的public 部分定义的嵌套类定义了可在任何地方使用的类型,在外围类的 protected 部分定义的嵌套类定义了只能由外围类、友元或派生类访问的类型,在外围类的 private 部分定义的嵌套类定义了只能被外围类或其友元访问的类型。
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.
选D
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.
A D
A. It calls the class default constructor for each element of the array.
B. It calls the class copy constructor for each element of the array.
C. It calls operator new[](size_t).
D. It calls operator new[](size_t, int).
E. It stores the number of objects allocated.
A C E
A. ~Y() ~X() ~A()
B. ~X() ~A() ~Y()
C. ~Y() ~A() ~X()
D. ~A() ~Y() ~X()
E. ~X() ~Y() ~A()
C
构造函数调用次序:基类构造函数(按申明顺序) 派生类成员变量构造函数 派生类自己构造函数
析构函数调用次序:与基类完全相反
public:
//...
//declaration goes here
};
A. char* operator();
B. char* operator char*();
C. String operator char*();
D. operator char*();
E. char* operator String();
D
2种会导致隐式类型转换的方法 1 单参数构造函数 2operator+类型名
B. new(pmem) SomeClass;
C. new pmem SomeClass;
D. new SomeClass pmem;
E. new (pmem, SomeClass);
B
C. When there is a need to check for the type of an object to determine which function must be called
D. When there is a need to check the value of a variable to determine which of two or more functions to call
E. When there is a need to modify the existing interface of a class
B C
B. Is-implemented-in-terms-of
C. Was-a
D. Can-only-have-one-of
E. Shares-a-relationship-with
B
B. Default arguments cannot be of a user-defined type.
C. Default arguments can never precede non-default arguments.
D. Default arguments exist in the global heap and not on the function's stack.
E. Default arguments are not considered for generating the function's signature.
C
Which of the following statements can be used to allocate memory for the first dimension in order to make p an array of 3 arrays of 5 pointers to type int?
A. p = new int [3][5]*;
B. p = new int (*)[3][5];
C. p = new int [3]*[5];
D. p = new int *[3][5];
E. p = new int (*[3])[5];
B. operator ++()
C. operator ==()
D. operator ()()
E. operator []()
D function object
Which of the following methods can the developer use to carry out this specialization?
A. void fn<char*>(char* a){...}
B. template <> void fn<char*>(char* a){...}
C. void fn<char*>(T a){...}
D. template <class T> void fn(char* a){...}
E. template <class T> void fn<char*>(T a){...}
B
"must not have known what you'd do."
B. #define GREETING = "Hello!"
C. #define MESSAGE = "This is a long message, but I know you have"
#define MESSAGE = MESSAGE + " plenty of time to read it."
D. #define ERROR_MSG "You did something very very wrong and now the \
program will terminate."
E. #define MESSAGE "Hello "
#concat MESSAGE & #UserName
D
B. A const std::type_info object
C. A const reference to a const std::type_info object
D. A reference to a std::type_info object
E. A const reference to a std::type_info object
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. 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.
D. Catching an exception by reference is preferable to catching it by value.
E. To write an exception handler, it is essential to know the concrete class of exception to catch.
B D
A. It only flushes the standard output stream.
B. It puts a newline character into the standard output stream and flushes the standard output stream.
C. It puts an end-of-output character into the standard output stream.
D. It only puts a newline character into the standard output stream.
E. It indicates end-of-output and closes the standard output stream.
B
B. The base class destructor cannot call the virtual function override of the derived class because the derived class portion of the data may be in an undefined state.
C. The base class destructor calls the virtual function of the base class and not of the derived class.
D. The C++ compiler maintains the overridden virtual function pointers in a separate structure when it sees the call in a destructor. The call is then resolved through this structure.
E. The language does not permit calling a virtual function override in either a constructor or the destructor of the base class.
B C
B C
A C D
B E
B D
10. B
11. A E
14.C
17. 输出为:
TestPrint
const TestPrint
volatile TestPrint
const volatile TestPrint
6. B D
11. B
12. A B D
14. C
19. C
23. D
24. A E
28. A B
30. B
31. A C
35. B
37. D
40. B
13. B D
36. A
58. C
10. B
25. D E
42. A C
54. BDE