Short Answer type Questions of C/C++ Language

1. What is the need for Destructors? 
Destructor is used to destroy an object. By destroying the object memory occupied by the object is released.

2. Explain the functions of Default Constructor.
The main function of the constructor is, if the programmer fails to create a constructor for a class, then the compiler will create a constructor by default in the name of class name without having any arguments at the time of compilation and provides the initial values to its data members. Since it is created by the compiler by default, the no argument constructor is called as default constructor.

3. What is the need for Overloading an operator. 
To define a new relation task to an operator, we must specify what it means in relation to the class to which the operator is applied. This is done with the help of a special function called operator function. It allows the developer to program using notation closer to the target domain and allow user types to look like types built into the language.

4. What are templates? 
Template is one of the features added to C++. It is new concepts which enable us to define generic classes and functions and thus provides support for generic programming. A template can be used to create a family of classes or functions.

5. Illustrate the exception handling mechanism. 
C++ exception handling mechanism is basically upon three keywords, namely, try, throw, and catch.
try – is used to preface a block of statements which may generate exceptions.
throw - When an exception is detected, it is thrown using a throw statement in the try block.
Catch- A catch block defined by the keyword catch ‘catches’ the exception ‘thrown’ by the thrown statement in the try block and handles its appropriately.

6. What happens when a raised exception is not caught by catch block? 
If the type of object thrown matches the arg type in the catch statement, then catch block is executed for handling the exception. If they do not match the program is aborted with the help of abort() function which is invoked by default. When no exception is detected and thrown, the control goes to the statement immediately after the catch block. That is the catch block is skipped.

7. What is a template? What are their advantages.
A template can be used to create a family of classes or functions. A template is defined with a parameter that would be replaced by a specified data type at the time of actual use of the class or functions. Supporting different data types in a single framework. The template are sometimes called parameterized classes or functions.

8. What is a virtual base class?
When a class is declared as virtual c++ takes care to see that only copy of that class is inherited, regardless of how many inheritance paths exist between the virtual base class and a derived class.

9. What is the difference between base class and derived class?
The biggest difference between the base class and the derived class is that the derived class contains the data members of both the base and its own data members. The other difference is based on the visibility modes of the data members.

10. What are the rules governing the declaration of a class of multiple inheritance?
a. More than one class name should be specified after the : symbol.
b. Visibility modes must be taken care of.
If several inheritance paths are employed for a single derived class the base class must be appropriately declared

11. Define dynamic binding. 
Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time.

12. What do you mean by pure virtual functions?
A pure virtual function is a function declared in a base class that has no definition relative to the base class. In such cases, the compiler requires each derived class to either define the function or re-declare it as a pure virtual function. A class containing pure virtual functions cannot be used to declare any objects of its own.


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: