1. Tell me when should we use container classes instead of arrays?

It is advisable to use container classes of the STL so that you don't have to go through the pain of writing the entire code for handling collisions, making sure its working well, testing it repeatedly with an overhead of time consumption.

Suppose you have some data that has values associated with strings and its fields consist of grades> in this situation you can directly use hash table instead of having it created by yourself.

2. Can you please explain the difference between homogeneous and a heterogeneous container?

A container is an object holding instances of another object. A container that contains or holds objects of a single type is said to be homogenous. On the other hand, A container that contains objects (derived from a common base class) of a variety of types is termed heterogeneous.

3. Do you know what is a container class? What are the types of container classes?

A class is said to be a container class which is utilized for the purpose of holding objects in memory or persistent media. A generic class plays a role of generic holder. A container class is a good blend of predefined behavior and an interface that is well known. The purpose of container class is to hide the topology for the purpose of objects list maintenance in memory. A container class is known as heterogeneous container, when it contains a set of different objects. A container class is known as homogeneous container when it contains a set of similar objects.

4. Explain different types of iterators, i.e. input_iterator, output_iterator etc?

Input Iterator: These iterators can read values in the forward movement. They can be incremented, compared and dereferenced.
Ouptut Iterator: They write values in the forward movement. They can be incremented and dereferenced.
Forward Iterator: They are like input and output iterators that can read and write values in forward movement.
Bidirectional iterators: These can Read and write values with forward and backward movement and can be incremented, decremented.
random_access_iterator: Can read and write values randomly.

5. What are the C++ standardized container classes?

The following are the standardized container classes:

std::map: Used for handle sparse array or a sparse matrix.
std::vector: Like an array, this standard container class offers additional features such as bunds checking through the at () member function, inserting or removing elements, automatic memory management and throwing exceptions.
std::string: A better supplement for arrays of chars.

6. Explain containers of pointer?

Container class is one of the classes that were put into class libraries. To handle objects that contain other objects, container classes are used. A GUI class library contains a group of container classes.

Containers of pointers provide containers to hold the objects that are heap-allocated in manner that is exception-safe and with minimum overhead. The central idea is to make OOP easier in C++. This is done by establishing a standard a set of classes, methods to deal with OO specific problems.

7. What is a container class? What are the types of container classes?

A class is said to be a container class which is utilized for the purpose of holding objects in memory or persistent media. A generic class plays a role of generic holder. A container class is a good blend of predefined behavior and an interface that is well known. The purpose of container class is to hide the topology for the purpose of objects list maintenance in memory. A container class is known as heterogeneous container, when it contains a set of different objects. A container class is known as homogeneous container when it contains a set of similar objects.

8. What are static automatic variables?

The static automatic variables, as with local variables, are accessible only within the function in which it is defined. Static automatic variables exist until the program ends in the same manner as external variables. In order to maintain value between function calls, the static variable takes its presence.

9. What are External variable?

External variable are defined outside any function and memory is set aside for this type of variable once it is declared and remained until the end of the program. These variables are also called global variables.

10. What is Automatic variable?

Automatic variable, also called as local variable and it has scope only within the function block where it is defined.

Download Interview PDF