C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » C++ programming language

C++ Interview Questions and Answers -1
(Basic, OOPS related)

This section contains basic C++ interview questions and answers related to programming techniques, object oriented programming systems and their components.

1) Define structured programming and its disadvantage?

It is a program design technique. In structured programming languages like C, Pascal, programmer defines data structure (arrays, structures, unions, enum etc) and the functions that perform operations on defined data structures.

But when program size grows up, then it becomes un-manageable, and data accidently modified by the different functions thus it generates logical errors or bugs in program.

2) Define OOPS?

OOPS stands for Object Oriented Programming System. It is also a program design technique, which is used to resolve problems of structured programming by binding data and function in a single unit called class. Here, data can be accessed only by the associated functions.

3) Define class?

Class is a logical encapsulation of data members and member functions in a single unit. It is a template of object. Class does not occupy any space in memory but when object creates, it occupies space in the memory according to data member. An empty class takes 1 byte space in memory.

For example, a HUMAN is a class and person "RAM" and "SHYAM" are the objects.

4) What is an Encapsulation?

It is a one of the basic feature of OOPS. Encapsulation means Binding data members and member functions in a single unit. Encapsulation can be useful to keep data safe from outside interfaces.

5) What is an Inheritance?

Inheritance is a mechanism (also an important component/feature of object oriented programming system) to inherit features from one to another class.

If we want to use/access existing features of any class, we can access them by using Inheritance. There will two classes Base class and Derived class.

If there is an existing class named "class_one" and new class named "class_two" that will access the features of class_one. In this case "class_one" will be considered as Base class and "class_two" as Derived class.

6) What is a polymorphism?

Polymorphism is the most important concept of OOPS. Polymorphism provides ability to use same name for different purposes.

In C++, functions and operators can be used to perform several (different) tasks by having same names. Two types of polymorphism are used:

  1. Static or Compile time polymorphism
    1. Function Overloading
    2. Operator Overloading
  2. Dynamic or Runtime polymorphism
    1. Virtual function or dynamic binding

7) What is an Abstraction?

Abstraction means hiding the implementation detail for simplicity. It is a good programming practice to keep implementation and interface independent. Abstraction allows doing the same.

We do not need to change interface, if we are going to change the implementation. Two types of abstractions are:

  1. Function abstraction
  2. Data abstraction

8) What is the difference between object based language and object oriented language?

OOBS does not support inheritance and polymorphism, whereas OOPS supports class, object, polymorphism, inheritance, abstraction etc.

9) What is the basic difference between Visual Basic and Visual C++?

Visual Basic is an object-based language; whereas Visual C++ is an object-oriented language.

10) What is the advantage of C++ being a block-structured language?

As we know that memory space is always premium. In block structured language, we can save memory space by controlling the life of variables.

For example:

void fun()
    //50 statement
        int x;
        //statement using x
    //100 more statement.

In the inner block, there is a variable x which will be declared when program’s control reaches to that block and freed when program’s control goes from that block. Thus it will not keep the memory save for a longtime.