Interview questions on c ++ for freshers/beginners

when and by whom c++ was developed?

Bjarne Stroustrup developed c++ at AT&T in the 1980’s.

What are constructors?

A class constructor is a special member function of a class that is executed whenever we create new objects of that class

How many types of Constructors are there?

There are five types of constructors:-

Default constructor.

Parameterized constructor.

Overload/multiple constructors.

Copy constructor

By default constructor

what is the need of a friend function?

A friend function is a non-member function of a class who can access private and protected members of the class.

When we don’t want to use polymorphism, what we can use a friend function instead.

What is oops?What are the basic concepts of oops?
OOPS stands for object oriented programming.
The basic concepts of OOPS are as follows:-
Objectsclasses

abstraction

encapsulation

inheritance

polymorphism

dynamic binding

What is a class?
Class: – A class is a blueprint of an object that explains the behavior and properties of a particular Object.

What are objects?object: -objects are those who have properties, state, and behavior.e.g.->human beings, we have color, we have sense, etc. properties.What is abstraction?

Abstraction is a process that throws necessary information, hiding the background details.

For e.g.-> A personal Computer. We press the power button of the CPU, and it starts. We do not need to open the CPU and make changes to the internal circuit to start it.

What is encapsulation?

Encapsulation is a process of merging complete data into a single unit.

E.g.->Tv remote or keyboard.

what is Inheritance?

Inheritance is the concept which allows extending a class with another class.

The ability of subclass acquiring the properties of super class is known as inheritance.

What is a subclass sand super class?

Superclass: – A class that allows other classes to extract its features called “superclass.”

Subclass: -the class who acquired the properties of another class is called “subclass.”

Disadvantages of inheritance?

Classes are tightly coupled.

A minute change in superclass will affect the subclass.

If super class deleted, the code will not work, and now subclass will work independently.

As classes coupled tightly, they cannot do work together.

What is polymorphism?

Polymorphism is the ability to take more than one form.

For e.g.  Organisms or species may have different forms or stages. This ability is referred as Polymorphism.

What are the types of polymorphism?

Run-time polymorphism.

Compile-Time polymorphism.

what is message passing?

The transfer of information or communication between objects through which objects can send and receive information with another known as message

passing.

What are tokens and its types?
The smallest individual unit in a program called tokens. In c++ following types of tokens are there:-
keywords

identifiers

constants

operators

define.function?
A function is a one which acts on data and returns a value.
What are Class members?
Class members are members of the class that consists of data members, define constructor and destructor functions and member functions.
What are a static class?
A static class is also a kind of a common class, but it cannot be instantiated means we cannot create an object as we cannot use new keyword inside a static class.

Define an array?
An array is a set of same data type.

Types of the array in c++?
Types of the array are as follow:-
1-d array.

2-D array.

Multidimensional array.

Define a string?
A string is a set of characters.
Types of Strings?
There are various kinds of Strings : –
Strlen

strupr

strlwr

strcpy etc.

define.access specifiers?
The access specifiers are the keywords which set the accessibility of classes, members and methods.
Types of access specifiers?
There are three types of access specifiers:-
Public.private.

protected.

Define.overloading?
Overloading allows c++ and other object oriented language to have the same name but with different parameters.
Define.virtual function?
Virtual function is that member function of a class whose functionality can be override in its derived class.
What is a pure virtual function?
A pure virtual function is a function with no body.
What are Concrete classes?
Concrete classes are logical abstract classes; they can be instantiated means objects can be created in concrete classes.
What is the use of scope resolution operator?
The scope resolution operator helps to identify and specify the context to which an identifier refers.
What are adaptor classes?
Adaptor classes are those who have the ability to modify the interface of a class and provide the new interface.
What is namespace?
Namespace identifies a name set so that there is no ambiguity when objects have different origins but same names are mixed.
Define pointers?
A pointer is a variable that holds the address stored in RAM.
Advantages of pointers?
Advantages are as follows: – It allows to return structured variables from functions. It allows variables, arrays as functions arguments passing.
Disadvantages of pointers?

Due to security concern, it seems to be dangerous as it can leak memory as it holds the address of the memory.So, that’s why in java “this” is used.

Define Expressions?
An expression is a sequence of operand and operators which specify the computation of values.

Primitive data types in c++?

Boolean

character

integer

float

double

Define Break statement?
Break statement forces the loop to exit immediately.
Define Continue statement?
Continue loop instead of terminating the loop will skip the rest of the code in a current block and will return to the evaluation part of the loop.

Define.friend function?
A friend function is a function that is not a member of a class but can gain access to private and protected class members.
What is a call by reference?
A function calls mechanism that passes arguments to a function by passing the addresses of the arguments.
What is the call by value?
A function calls mechanism that passes arguments to a function by passing a copy of the value of the arguments.
Define.inline function?
Inline functions behave like a placeholder. Define inline function once, using the ‘inline’ keyword, whenever you call that function the compiler will replace the function call with the actual code from the function.
How many types of statements used in c++?
List of statements used in c ++ are:-
If

switch

goto

while

do while

break

continue

if else etc.