C++测试题练习题1

1、which of the following is not automatically generated by the compiler?

      a. default constructor    b. copy constructor    c. equality operator(op==)     d. assignment operator(op=)       e. destructor

2、which of the following is not an STL collection?

      a. vector   b. list     c. map    d. tree      e. set

3、which statement is false?

      a. Destructors are called when a pointer is deleted.     

      b. Destructors are called when an object goes out of scope.

      c. Destructors are called when a reference goes out of scope.

      d. A virtual destructor should be used if the class has virtual methods.

      e. Base class destructors are called after derived class destructors.

4、what should you avoid calling from a constructor?

       a. a static method    b. an inlined method       c. a virual method      d. a const method          e. an extern method

5、which of the following C++ operators cannot be overloaded?

       a. <<           b. []             c. ++             d. ()               e. :?

6、Consider the following function:

void foo(const char* name) 
{ 
     char* Name1 = name;            //Statement1 
     const char* Name2 = name;   //Statement2 
     char* const Name3 = name;   //Statement3 
     char const* Name4 = name;   //Statement4 
} 

 which of the following is true?

    a. Statement 1 fails to compile                   b. Statement 1 and 3 fails to compile

    c. Statement 3 and 4 fails to compile          d. Statment 2 fails to compile

    e. Statment 3 and 4 fails to compile

7、Consider the following code:

struct MyStruct
{ 
     int foo(){return 1;}
};
 class MyClass
{ 
      int foo(){ return 2;}
}; 
MyStruct s; 
MyClass c; 
***** 
int x = s.foo();   //Statement1 
int y = c.foo();    //Statement2

Circle one answer below which is true of the above code.

       a. Statement 1 will cause a compilation error                     b. Statement 2 will cause a compilation error

       c. Both statement will compilation successfully                   d. Both statement will fail to compile

8、Consider the following class:

class ClassX 
{ 
    public: ClassX():C_(1),B_(2),A_(B_+C_){} 

     private: 
          int A_; 
          int B_;
          int C_; 
};

 what value will the member variable A be initialized to?

       a. 0          b. 1             c. 2                d. 3                 e. None of the above

9、Name the design pattern that is implemented in the following C++ class:

class XXX 
{ 
     public: 
    static XXX * instance() 
         { 
          static XXX x; return &x; 
         } 
      protected: 
      { 
       XXX(){} 
       }
 }; 

a. proxy b. composite c. singleton d. factory e.adapter

10 
class
Foo { public: virtual void cala() { cout << "foo"<<end1; } } class Bar : public Foo { public: void calc() { cout << "bar"<<end1; } } int main() { Bar * b1 = new Bar(); Bar b2; Foo f1 = *b1; Foo &f2 = b2; Foo *f3 = b1; f1.calc(); f2.calc(); f3.calc(); }

which of the output of the above code?

           a. foo foo foo     b. foo bar   bar       c. foo   foo    bar       d. bar    bar   bar     e.   bar  foo bar 

posted on 2014-12-19 22:27 搬运工 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/CD-lulu/p/4174775.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值