Constructors And Destructors In C Plus Plus — Part 2 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Constructors And Destructors In C Plus Plus — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
28
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
34 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
28
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/28 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 28 questions answered.
Question 1 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ int a; public: A(int i){ a = i; } void assign(int i){ a = i; } int return_value(){ return a; } }; int main(int argc, char const *argv[]) { A obj; obj.assign(5); cout<<obj.return_value(); }
Correct Answer: Option C — Error
Detailed Academic Explanation:
Error is the correct answer to “What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ int a; public: A(int i){ a = i; } void assign(int i){ a = i; } int return_value(){ return a; } }; int main(int argc, char const *argv[]) { A obj; obj.assign(5); cout<<obj.return_value(); }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 2 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many types of constructors are there in C++?
Correct Answer: Option C — 3
Detailed Academic Explanation:
3 is the correct answer to “How many types of constructors are there in C++”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 3 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ A(){ cout<<"Constructor called"; } }; int main(int argc, char const *argv[]) { A a; return 0; }
Correct Answer: Option C — Error
Detailed Academic Explanation:
Error is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ A(){ cout<<"Constructor called"; } }; int main(int argc, char const *argv[]) { A a; return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 4 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(){ cout<<"Constructor called"; } }; int main(int argc, char const *argv[]) { A *a1 = (A*)malloc(sizeof(A)); return 0; }
Correct Answer: Option B — Nothing printed
Detailed Academic Explanation:
Nothing printed is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(){ cout<<"Constructor called"; } }; int main(int argc, char const *argv[]) { A *a1 = (A*)malloc(sizeof(A)); return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 5 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following constructors are provided by the C++ compiler if not defined in a class?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “Which of the following constructors are provided by the C++ compiler if not defined in a class”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 6 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: A(){ cout<<"Constructor called"; } }; int main(int argc, char const *argv[]) { A *a; return 0; }
Correct Answer: Option B — Nothing printed
Detailed Academic Explanation:
Nothing printed is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: A(){ cout<<"Constructor called"; } }; int main(int argc, char const *argv[]) { A *a; return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 7 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(int a=0){ this->a = a; } }; int main(int argc, char const *argv[]) { A a1, a2(10); cout<<a2.a; return 0; }
Correct Answer: Option A — 010
Detailed Academic Explanation:
010 is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(int a=0){ this->a = a; } }; int main(int argc, char const *argv[]) { A a1, a2(10); cout<<a2.a; return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 8 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(){ cout<<"Constructor called"; } } a; int main(int argc, char const *argv[]) { return 0; }
Correct Answer: Option A — Constructor called
Detailed Academic Explanation:
Constructor called is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(){ cout<<"Constructor called"; } } a; int main(int argc, char const *argv[]) { return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 9 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(int a){ this->a = a; } }; int main(int argc, char const *argv[]) { A a1, a2(10); cout<<a2.a; return 0; }
Correct Answer: Option B — Compile time error
Detailed Academic Explanation:
Compile time error is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(int a){ this->a = a; } }; int main(int argc, char const *argv[]) { A a1, a2(10); cout<<a2.a; return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 10 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ mutable int a; public: A(){ cout<<"A's default constructor called\n"; } A(const A& a){ cout<<"A's copy Constructor called\n"; } }; class B{ A obj; public: B(){ cout<<"B's Constructor called\n"; } }; int main(int argc, char const *argv[]) { B b1; B b2; }
Correct Answer: Option C — A's default constructor called B's Constructor called A's default constructor called B's Constructor called
Detailed Academic Explanation:
A's default constructor called B's Constructor called A's default constructor called B's Constructor called is the correct answer to “What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ mutable int a; public: A(){ cout<<"A's default constructor called\n"; } A(const A& a){ cout<<"A's copy Constructor called\n"; } }; class B{ A obj; public: B(){ cout<<"B's Constructor called\n"; } }; int main(int argc, char const *argv[]) { B b1; B b2; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 11 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Why constructors are efficient instead of a function init() defined by the user to initialize the data members of an object?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “Why constructors are efficient instead of a function init() defined by the user to initialize the data members of an object”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 12 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ A(){ cout<<"A's Constructor called\n"; } }; class B { public: A a; B(){ cout<<"B's constructor called\ns"; } }; int main(int argc, char const *argv[]) { B b; return 0; }
Correct Answer: Option C — Error
Detailed Academic Explanation:
Error is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ A(){ cout<<"A's Constructor called\n"; } }; class B { public: A a; B(){ cout<<"B's constructor called\ns"; } }; int main(int argc, char const *argv[]) { B b; return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 13 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a copy constructor?
Correct Answer: Option B — A constructor to initialize an object with the values of another object
Detailed Academic Explanation:
A constructor to initialize an object with the values of another object is the correct answer to “What is a copy constructor”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 14 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
When a copy constructor is called?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “When a copy constructor is called”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 15 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following represents the correct explicit call to a constructor of class A? class A{ int a; public: A(int i) { a = i; } }
Correct Answer: Option C — A a = A(5)
Detailed Academic Explanation:
A a = A(5) is the correct answer to “Which of the following represents the correct explicit call to a constructor of class A? class A{ int a; public: A(int i) { a = i; } }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 16 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ ~A(){} }; class B { public: A a; }; int main(int argc, char const *argv[]) { B b; return 0; }
Correct Answer: Option C — Error
Detailed Academic Explanation:
Error is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ ~A(){} }; class B { public: A a; }; int main(int argc, char const *argv[]) { B b; return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 17 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many parameters does a default constructor require?
Correct Answer: Option C — 0
Detailed Academic Explanation:
0 is the correct answer to “How many parameters does a default constructor require”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 18 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In the following C++ code how many times the string "A's constructor called" will be printed? #include <iostream> #include <string> using namespace std; class A{ int a; public: A(){ cout<<"A's constructor called"; } }; class B{ static A a; public: B(){ cout<<"B's constructor called"; } static A get(){ return a; } }; A B::a; int main(int argc, char const *argv[]) { B b; A a1 = b.get(); A a2 = b.get(); A a3 = b.get(); }
Correct Answer: Option D — 1
Detailed Academic Explanation:
1 is the correct answer to “In the following C++ code how many times the string "A's constructor called" will be printed? #include <iostream> #include <string> using namespace std; class A{ int a; public: A(){ cout<<"A's constructor called"; } }; class B{ static A a; public: B(){ cout<<"B's constructor called"; } static A get(){ return a; } }; A B::a; int main(int argc, char const *argv[]) { B b; A a1 = b.get(); A a2 = b.get(); A a3 = b.get(); }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 19 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the role of destructors in Classes?
Correct Answer: Option B — To destroy an object when the lifetime of an object ends
Detailed Academic Explanation:
To destroy an object when the lifetime of an object ends is the correct answer to “What is the role of destructors in Classes”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 20 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is syntax of defining a destructor of class A?
Correct Answer: Option B — ~A(){}
Detailed Academic Explanation:
~A(){} is the correct answer to “What is syntax of defining a destructor of class A”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 21 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens if a user forgets to define a constructor inside a class?
Correct Answer: Option D — Compiler provides a default constructor to avoid faults/errors
Detailed Academic Explanation:
Compiler provides a default constructor to avoid faults/errors is the correct answer to “What happens if a user forgets to define a constructor inside a class”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 22 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; }; int main(int argc, char const *argv[]) { A a1 = {10}; A a2 = a1; cout<<a1.a<<a2.a; return 0; }
Correct Answer: Option A — 1010
Detailed Academic Explanation:
1010 is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; }; int main(int argc, char const *argv[]) { A a1 = {10}; A a2 = a1; cout<<a1.a<<a2.a; return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 23 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(){ cout<<"Constructor called\n"; } } a; int main(int argc, char const *argv[]) { cout<<"Main function\n"; return 0; }
Correct Answer: Option A — Constructor called Main function
Detailed Academic Explanation:
Constructor called Main function is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(){ cout<<"Constructor called\n"; } } a; int main(int argc, char const *argv[]) { cout<<"Main function\n"; return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 24 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ int a; A(){ a = 5; } public: void assign(int i){ a = i; } int return_value(){ return a; } }; int main(int argc, char const *argv[]) { A obj; obj.assign(10); cout<<obj.return_value(); }
Correct Answer: Option C — Error
Detailed Academic Explanation:
Error is the correct answer to “What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ int a; A(){ a = 5; } public: void assign(int i){ a = i; } int return_value(){ return a; } }; int main(int argc, char const *argv[]) { A obj; obj.assign(10); cout<<obj.return_value(); }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 25 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ mutable int a; public: A(){ cout<<"A's Constructor called\n"; } ~A(){ cout<<"A's Destructor called\n"; } }; class B: public A{ A a; public: B(){ cout<<"B's Constructor called\n"; } ~B(){ cout<<"B's Destructor called\n"; } }; int main(int argc, char const *argv[]) { B b1; }
Correct Answer: Option C — A's Constructor called A's Constructor called B's Constructor called B's Destructor called A's Destructor called A's Destructor called
Detailed Academic Explanation:
A's Constructor called A's Constructor called B's Constructor called B's Destructor called A's Destructor called A's Destructor called is the correct answer to “What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ mutable int a; public: A(){ cout<<"A's Constructor called\n"; } ~A(){ cout<<"A's Destructor called\n"; } }; class B: public A{ A a; public: B(){ cout<<"B's Constructor called\n"; } ~B(){ cout<<"B's Destructor called\n"; } }; int main(int argc, char const *argv[]) { B b1; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 26 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ A(){ cout<<"A's Constructor called\n"; } friend class B; }; class B { public: A a; B(){ cout<"B's constructor called\ns"; } }; int main(int argc, char const *argv[]) { B b; return 0; }
Correct Answer: Option A — A's Constructor called B's constructor called
Detailed Academic Explanation:
A's Constructor called B's constructor called is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ A(){ cout<<"A's Constructor called\n"; } friend class B; }; class B { public: A a; B(){ cout<"B's constructor called\ns"; } }; int main(int argc, char const *argv[]) { B b; return 0; }”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 27 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the role of a constructor in classes?
Correct Answer: Option C — To initialize the data members of an object when it is created
Detailed Academic Explanation:
To initialize the data members of an object when it is created is the correct answer to “What is the role of a constructor in classes”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
Question 28 of 28
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many Destructors are allowed in a Class?
Correct Answer: Option A — 1
Detailed Academic Explanation:
1 is the correct answer to “How many Destructors are allowed in a Class”. This question is standard in competitive examination syllabi for Constructors And Destructors In C Plus Plus.
💡Key Conceptual Anchor:Constructors And Destructors In C Plus Plus
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.