C++ MCQs

C++ OOP, pointers, STL, templates, memory management, and references.

22 MCQsProgrammingAll Levels
Key Concept Overview & Exam Context

Review core principles of C++ before answering questions. These questions simulate placement technical assessments (TCS, Infosys, Amazon), university exams (CS/IT), and technical certifications.

Target Readiness
Placements & Job Interviews
Question Format
Multiple-Choice with Explanations
Verified Solutions
Step-by-step Output Traces

C++ MCQ Questions

Page 1 of 2 (22 total)
Q1

What is the purpose of a constructor in C++?

easy
Correct Answer: To initialize an object's data members automatically when the object is created
Explanation:
A constructor shares the same name as its class and runs automatically whenever a new object is instantiated, ensuring the object starts in a valid, properly initialized state.
Q2

What is the difference between a pointer and a reference in C++?

medium
Q3

What is a virtual function in C++?

hard
Q4

What is the purpose of a destructor in C++?

medium
Q5

What is function overloading in C++?

easy
Q6

What is the purpose of the 'const' keyword when applied to a function parameter in C++?

medium
Q7

What is the diamond problem in C++?

hard
Q8

What is the purpose of the 'new' operator in C++?

medium
Q9

What is operator overloading in C++?

hard
Q10

What is the purpose of the 'this' pointer in C++?

medium
Q11

What is a template in C++ used for?

hard
Q12

What is the difference between a struct and a class in C++?

medium
Q13

What does the C++ Standard Template Library (STL) provide?

medium
Q14

What is the purpose of the 'friend' keyword in C++?

hard
Q15

What happens if a class in C++ does not explicitly define a destructor?

medium
Q16

What is the difference between pass by value and pass by reference in C++ function calls?

medium
Q17

What is the purpose of namespaces in C++?

medium
Q18

What is a smart pointer in modern C++?

hard
Q19

What is the difference between compile-time polymorphism and runtime polymorphism in C++?

hard
Q20

What is the purpose of an inline function in C++?

hard
Showing 1 to 20 of 22 questions