C 常见英文面试笔试题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C/C++ Programmi ng in terview questi ons and
an swers
By Satish Shetty, July 14th, 2004
What is encapsulation??
Containing and hiding information about an object, such as internal data structures and code. Encapsulation isolates(使隔离)the internal complexity of an object's operation from the rest of the applicati on. For example, a clie nt comp onent ask ing for net revenue (收益)from a bus in ess object n eed not know the data's origi n.
What is inheritance?
Inheritance allows one class to reuse the state and behavior of another class. The derived class inherits the properties and method implementations of the base class and extends it by overriding methods and addi ng additi onal properties and methods.
What is Polymorphism??
Polymorphism allows a clie nt to treat differe nt objects in the same way even if they were created from different classes and exhibit (展现)different behaviors.
You can use implementation (实现)inheritance to achieve polymorphism in Ianguages such as
C++ and Java.
Base class object's pointer can invoke (调用)methods in derived class objects.
You can also achieve polymorphism in C++ by fun cti on overloadi ng and operator overloadi ng.
What is constructor or ctor?
Constructor creates an object and initializes it. It also creates vtable 变量歹U表?for virtual function s. It is differe nt from other methods in a class.
What is destructor?
Destructor usually deletes any extra resources allocated by the object.
What is default constructor?
Con structor with no argume nts or all the argume nts has default values.
What is copy constructor?
Con structor which in itializes the it's object member variables ( by shallow copy ing) with ano ther object of the same class. If you don't implement one in your class then compiler implements one for you. for example:
Boo Obj1(10); // calling Boo constructor
Boo 0bj2(0bj1); // calli ng boo copy con structor
Boo Obj2 = Obj1;// call ing boo copy con structor
When are copy constructors called?
Copy con structors are called in follow ing cases:
a) whe n a fun ctio n returns an object of that class by value
b) whe n the object of that class is passed by value as an argume nt to a function
c) whe n you con struct an object based on ano ther object of the same class
d) When compiler gen erates a temporary object
What is assignment operator?
Default assig nment operator han dles assig ning one object to ano ther of the same class. Member to member copy (shallow copy)
What are all the implicit member functions of the class?Or what are all the functions which compiler implements for us if we don't define one.??
default ctor
copy ctor
assig nment operator
default destructor
address operator
What is conversion constructor?
con structor with a sin gle argume nt makes that con structor as conversion ctor and it can be used for type conversion.
for example:
class Boo
{
public:
Boo( int i );
};
Boo BooObject = 10 ; // assig ning int 10 Boo object
What is conversion operator??
class can have a public method for specific data type conversions.
for example:
class Boo
{
double value;
public:
Boo(i nt i )
operator double()
{
return value;
};