Top C++ Interview Question and Answer 2023

Updated:01/22/2023 by shubham Mishra
One must be completely prepared for the interview questions in order to speak with the interviewer.
We'll go over some of the programming, output-based, and conceptual questions based on inheritence , Object ,class , constructor , Pointer , File Handling , Overloading , overriding etc ,you may  required in a C++ interview.
Here we can see property of C++ language :-
  • Both virtual and friend functions are supported by the C++ language.
  • There are 52 keywords in C++.
  • Function and function overloading are supported in C++.
Top 50 C++ Interview and Question


Q.1 Define classes and objects in C++?
Ans: A class is like a blueprint of an object.
It is a user-defined data type with data members and member functions and is defined with the keyword class.
InterviewQuestions_Example1.
You define objects as an instance of a class. Once it creates the object, then it can operate on both data members and member functions.

Q.2 What are access modifiers?
Ans: You use access modifiers to define accessibility for the class members. It defines how to access the members of the class outside the class scope.
    There are three types of access modifiers:
  • Private
  • Public
  • Protected

Q.3 Difference between equal to (==) and assignment operator(=)?
Ans: The equal to operator == checks whether two values are equal or not.
If equal, then it’s true; otherwise, it will return false.
The assignment operator = allots the value of the right-side expression to the left operand.

Q.3 What is the difference between a while loop and a do-while loop?
Ans: The while loop verifies the condition; if it’s true, then it iterates the loop till the condition becomes false.

The do-while loop first iterates the loop then checks for the condition.

Syntax:

while (condition)

{

statements

}

Syntax:

do{

statements

}

while(condition);

If the condition is false in a while loop, then not a single statement will execute inside the loop.

If the condition in a do-while loop is false, then the body will also execute once.

Get the Must-Have Skills of a Web Developer
Caltech Coding BootcampEXPLORE PROGRAMGet the Must-Have Skills of a Web Developer

Q.4 What is the size of the int data type?
Ans: the integer data type is 4 bytes.

Q.5 Which among the following operators cannot be overloaded?
-
+
?:
%
Ans: Answer is (3) ? :operator cannot be overloaded because it is not syntactically possible.

Q.6 what is new operator in C++ ?
Ans: It calls the constructor,There is no need to specify memory size while using new()and new operator can be overloaded.

Q.7 what is malloc function in C++?
Ans: malloc() is a function ,The malloc function doesn’t call the constructor,You have to specify the memory size

Q.8 What is STL?
Ans: STL stands for standard template library. It is a library of container templates that provide generic classes and functions.

Q.9 What is Abstraction?
Ans: Abstraction can be defined as a technique in which you only show functionality to the user i.e., the details that you want the user to see, hiding the internal details or implementation details.

Q.10 What should be the correct statement about string objects in C++?
1)String objects should necessarily be terminated by a null character
2)String objects have a static size.
3)String objects have a dynamic size.
4)String objects use extra memory than required.
Ans: String objects have a dynamic size.

Q.11 Which of the following is not a member of a class?
Ans: friend function is not a member of the class

Q.12 Can a virtual function be called from a constructor?
Ans: you should never call virtual functions in constructors or destructors.

Q.13 What are void pointers?
Ans: Void pointer has no connection to any particular data type.

Q.14 What is a friend function?
Ans: You can define a friend function as a function that can access private, public and protect members of the class. You declare the friend function with the help of the friend keyword. You declare this function inside the class.

Q.15 What is operator overloading?
Ans: Overloaded operators are functions with special names: the keyword 'operator' followed by the symbol for the operator being defined.
C++ has the ability to provide the operators with a special meaning for a data type, this ability is known as operator overloading.

Q.16 What is operator overriding ?
Ans: C++ is a concept by which you can define a function of the same name and the same function signature (parameters and their data types) in both the base class and derived class with a different function definition.

Q.17 What is a scope resolution operator?
Ans: A scope resolution operator is represented as ::

Q.18 How to define Inline function .
Ans:
Syntax:

Inline return-type function-name(parameters)
{

}

Q.19 What is call by reference in C++ ?
Ans: In this method, it passes the address of the variable as an argument,
In this method, the actual value is modified.

Q.20 What is call by value in C++ ?
Ans: In this method, it passes the value of the variable as an argument.
In this method, the actual value is not modified.

Q.21 Define Object in OOPs.
Ans: Object: Anything that exists physically in the real world is called an object.

Q.22 Define Class in OOPs.
Ans: Class: The collection of objects is called class.

Q.23 Define Inheritance in OOPs.
Ans: Inheritance: Properties of parent class inherited into child class is known as inheritance.

Q.24 Define Inheritance in OOPs.
Ans: Polymorphism: It is the ability to exist in more than one form.

Q.25 Define Inheritance in OOPs.
Ans: Encapsulation: Binding of code and data together into a single unit.

Q.26 Define Inheritance in OOPs.
Ans: Abstraction: Hiding internal details and showing functionality to the user.

Q.27 when abstract class is used?
Ans: Placing a pure virtual function in the class makes it an abstract class.

Q.28 It is possible to overload a deconstructor ?
Ans: It is impossible as destructors do not take arguments or return anything.

Q.29 What is Public specifiers in C++ ?
Ans: All member functions and data members are accessible outside the class.

Q.30 What is Protected specifiers in C++ ?
Ans: All member functions and data members are accessible within the class and to the derived class.

Q.31 What is Private specifiers in C++ ?
Ans: All member functions and data members cannot be accessed outside the class.