C++ Interview Questions and Answers

What is C++?

C++ is an object-oriented programming language created by Bjarne Stroustrup in 1985.

What are the differences between C and C++?

C++ is a superset of C language.

C is a procedural programming language, but C++ supports both procedural and Object Oriented programming.

In C++ can use access modifier to restrict access of member function and variable to outside class and user, but in C we can’t do that.

What are the differences between C++ and Java?

C++ has pointers, but Java does not support pointer.
Java is platform-independent, but C++ is not.
Java has garbage collection, but C++ does not.
C++ used complier but Java uses interpreter.
C++ support operator overloading and multiple inheritance but Java not support both.

Explain is Object Oriented Programming (OOP)?

Object-oriented programming is a techniques for managing enormous complexity, achieving reuse of software components, and coupling data with the procedures that work on that data as a single "object"--a self-contained entity.

The basic concepts of Object Oriented Programming are given below:
Class and Object: Class is a template and implementation of entities whereas Object is variable and representation of class.
Encapsulation and data hiding: the binding of data and methods together called Encapsulation, where hide the data or direct access from outside known as data hiding.
Inheritance: Inheritance is concept of reusability and can used this to inherit the property of one class into another class.
Polymorphism: Poly means many, and morph means form. Polymorphism refers to the same name taking many forms or can perform different task depend on context.

What is a class in C++?

Class is a user-defined data type. It can consist of any combination of the variable types and also other class types.
The variables in the class are referred to as the member variables or data members and the functions in the class referred to as member Functions or methods of the class.

What is an object?

An object is an individual instance of a class and also called a class variable.
It can access the class members and functions by using the dot (.) operator.

Define the private, public and protected in C++?

Private, Public and protected and are three access specifier in C++.

Private: All members of a class data and methods are private by default. Private members can be accessed only within methods of the class itself.
Public: Public members can be accessed through any object of the class.
Protected: data members and member functions are only available to derived classes.

Explain constructor?

Constructors is special member function of class with the same name as the class and it used to create and initialize Object.
The constructor can take parameters as needed, but it cannot have a return value--not even void.
We can do Overloading of Constructor.

Explain destructor?

Destructors always has the name of the class, preceded by a tilde (~) and clean up allocated memory. Destructors take no arguments and have no return value.
We cannot Overload of destructor.

What is Default Constructors and Destructors?

If we don't declare a constructor or a destructor manually, the compiler makes one for you. The default constructor and destructor take no arguments and do nothing.

What is a copy constructor?

A copy constructor is the constructor which copies the exact values of one object's member variables into another object.
Copy constructors take one parameter, which a reference to an object of the same class.

Explain the static variable and member function?

Static variables and member functions belonging to the class rather than to the object. Normal member data is one per object, but static members are one per class and they can be called without having an object of that class.

 

What is a friend function?

A function which is not a member of the class but still can access all private and protected member data and functions of the class.
Function can declare friend by using the keyword friend and then the full specification of the function.

 

What is Inheritance?

Inheritance is the process of acquiring the properties of the existing class into the new class.
A class which adds new functionality to an existing class is said to derive from that original class. The original class is said to be the new class's base class.

 

What is function overriding?

A derived class creates a function with the same return type and signature (function name, as well as the number and type of its Parameters) as a member function of the base class, but with a new implementation, it is said to be overriding that method.

 

What is polymorphism?

Polymorphism is the ability to treat many objects of differing but related types without regard to their differences.

 

Latest Updates

Ratio and Proportion

175 men can dig a canal of 3150 meters long in 36 days. How many men are required to dig a canal of 3900 meters long in 24 days?

24 men working at 8 hours a day can do a piece of work in 15 days. In how many days can 20 men working at 9 hours a day do the same work?

10 men can lay a road of 75 Km long in 5 days. In how many days can 15 men lay a road of 45 Km long?

Rice costing Rs. 480/- is needed for 8 members for 20 days. What is the cost of rice required for 12 members for 15 days?

The mess charge for 35 students for 24 days is Rs. 6300/-. In how many days will the mess charges be Rs. 3375/- for 25 students?

Time and Work

18 men can dig a well in 10 days. After they have worked for 4 days, how many more men shall be employed to complete the work in 4 days from then?

If 80 men can do a piece of work in 10 days, how many men are required to do the same work in 4 days?

If 80 men can do a piece of work in 10 days, in how many days can 40 men do the same piece of work?

General Computer Knowledge

What kind of material does ‘IC’ in computers made of?

Physics

The force required to produce an acceleration of 4 m/s2 in an object of mass 9 kg is?

Biology

Some seeds have hooks and spines. It helps the seeds to__________?

Physics

Which of the following modes of heat transfer is faster?

Agriculture

Which of the following reproduces from underground stem?

Botany

Lichens are a symbiotic association of?

Physics

The unit of relative density is?

Problems on Ages

The ages of Gyanendra and Jitendra are in the ratio of 12:7 respectively. After 6 years, the ratio of their ages will be 3:2 respectively . find the difference in their ages?

Time and Work

X can do a piece of work in 20 days, while Y can do in 10 days. If Y worked at it for 8 days,then X can finish the remaining work in______.?

Coding-Decoding

In a certain code, BELIEF is written as AFKKDI. How is SELDOM written in that code?