一份英文面试题

分数是没有的,东西是有趣的。


C++ Questions


Part 1: Basic Questions

Question 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


Question 2:
Which of the following is not an STL collection?

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


Question 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.
 
Question 4:
What should you avoid calling from a constructor?

a) a static method
b) an inlined method
c) a virtual method
d) a const method
e) an extern method


Question 5:
Which of the following C++ operators cannot be overloaded?

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

 
Part 2: Intermediate Questions


Question 6:  
Consider the following function:

void foo(const char* name)  
{
char* Name1 = name;        // Statement 1
const char* Name2 = name;  // Statement 2
char* const Name3 = name;  // Statement 3
char const* Name4 = name;  // Statement 4
}

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) Statement 2 fails to compile.
e) Statement 3 and 4 fails to compile.


Question 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(); // Statement 1
int y = c.foo(); // Statement 2

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 statements will compile successfully
d) Both statements will fail to compile

 
Question 8:
Consider the following code:

class Mammal : public Animal { … }

What is the best way to convert an Animal into a Mammal?

a) const_cast <Mammal *>
b) static_cast <Mammal *>
c) reinterpret_cast <Mammal *>
d) dynamic_cast <Mammal *>
e) (Mammal *)


Question 9:
Consider the following code:

std::auto_ptr <int>  value1(new int(1));
std::auto_ptr <int>  value2(new int(2));
std::auto_ptr <int>  value3(new int(3));

value2 = value1;
value3 = value1;

cout  < < *value3  < < endl;

What value will be printed to standard out?

a) 1
b) 2
c) 3
d) The pointer address
e) None of the above


Question 10: 
What is the result of the expression (0x03  ¦ 0x01)?

a) 0x01
b) 0x02
c) 0x03
d) 0x04
e) 0x05
 
Question 11:
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


Question 12:

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

 
Question 13:

class Foo
{
public:
    virtual void calc() { cout  < < "foo"  < < endl; }
};

class Bar : public Foo
{
public:
    void calc() { cout  < < "bar"  < < endl; }
};

int main()
{
    Bar* b1 = new Bar();
    Bar  b2;

    Foo  f1 = *b1;
    Foo& f2 =  b2;
    Foo* f3 =  b1;

    f1.calc();
    f2.calc();
    f3-> calc();
}

What is 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
 
Question 14:

class Mutex
{
public:
    void acquire();
    void release();
};

class ThreadSafe
{
private:
    Mutex m;

public:
    void op() const
    {
        m.acquire();
        m.release();
    }
};

Which of the following C++ keywords can be used to make the code compile?

a) volatile
b) mutable
c) auto
d) inline
e) explicit


Question 15:
What best describes virtual inheritance?

a) A derived class which does not implement abstract methods.
b) A derived class which adds abstract methods to a concrete base class.
c) A multiply inherited class with multiple copies of its base class.
d) A multiply inherited class with one copy of its base class.
e) All of the above.  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值