C++ Programming Interview Questions and Answers - 1

Question: 1

What is the difference between late binding and early binding?

Late binding refers to functions calls that are not resolved until run time while early binding refers to the events that occur at compile time.

Late binding occurs through virtual functions while early binding takes place when all the information needed to call a function is known at the time of compiling.

Early binding increases the efficiency. Some of the examples of early binding are normal function calls, overloaded function calls, and overloaded operators etc.

Question: 2

Define a constructor?

Constructor is a member functions of the class, with the name of the functions being the same as the class name. It also specifies how the object should be initialized.

Ways of calling constructor:

Implicitly: automatically by compiler when an object is created.

Calling the constructor explicitly is possible, but it makes the code unverifiable.

Question: 3

What is Standard Template Library (STL)?

A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification.

A programmer who then launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher than average understanding of the new technology that STL brings to C++ programming.

Question: 4

What are virtual functions?

A virtual function allows derived classes to replace the implementation provided by the base class.

The compiler make sure the replacement is always called whenever the object in question is actually of the derived class, even if the objects is accessed by a base pointer rather than a derived class, even if users don’t know about the derived class.

Question: 5

What is friend function?

As the name suggests, the function acts as a friend to a class.

As a friend of a class, it can access its private and protected members.

A friend function is not a member of the class. But it must be listed in the class definition.

Related Questions