MCQ on Destructor in C++: Multiple Choice Questions on C++ Destructor

MCQ on destructor in C++ with answers and explanations for placement tests and job interviews. This C++ MCQ on destructor is useful for the campus placement for all freshers including Engineering Students, MCA students, Computer and IT Engineers, etc.

Our C++ destructor quiz (C++ destructor multiple Choice Questions ) focuses on all areas of the C++ destructor and its concept. We will regularly update the MCQ on the C++ destructor and most interesting thing is that questions come in a random sequence. So every time you will feel new questions.

You may have come across several C++ courses during your search for learning the C++ language. Our team of experts has carefully analyzed some C++ courses for you. You can check the courses, Trial of some courses is free.

 

Guideline of MCQ on destructor in C++:

This MCQ on destructor in C++ is intended for checking your knowledge of C++ destructors. It takes 30 minutes to pass the C++ quiz on the destructor. If you don’t finish the C++ destructor quiz within the mentioned time, all the unanswered questions will count as wrong. Every unanswered question will count as wrong. MCQ on destructor in C++ has randomization features that give you a new question set at every attempt.

In this MCQ on destructor in C++, we have also implemented a feature that does not allows the user to see the next question or finish the quiz without attempting the current C++ destructor quiz.

0 votes, 0 avg

You have 20 minutes to take the MCQs on Destructor in C++

Your time has been Over.


MCQ on Destructors in C++

C++ MCQ

MCQ on Destructors in C++: Multiple Choice Questions and Answers on Destructors in C++

1 / 14

Like constructors, can there be more than one destructors in a class?

2 / 14

Can destructors be virtual in C++?

3 / 14

Can I overload the destructor for my class?

4 / 14

Can destuctors be private in C++?

5 / 14

Which of the following statements are not true about destructor?

1. It is invoked when the object goes out of the scope
2. Like a constructor, it can also have parameters
3. It can be virtual
4. It bears the same name as that of the class and precedes the Lambda sign.

6 / 14

Could we destroy local objects within the function?

7 / 14

What’s the order that local objects are destructed?

int main()
{
    Test obj1;
    
    Test obj2;
    
    return 0;
}

 

8 / 14

When I write a derived class’s destructor, do I need to explicitly call the destructor for my base class?

9 / 14

What’s the order that sub-objects of an object are destructed?

struct Base0
{
    ~Base0() {};
};
struct Base1
{
    ~Base1() {};
};
struct Member0
{
    ~Member0() {};
};
struct Member1
{
    ~Member1() {};
};
struct Local0
{
    ~Local0()
    {

    };
};
struct Local1
{
    ~Local1()
    {

    };
};
struct Derived: Base0, Base1
{
    Member0 m0_;
    Member1 m1_;
    ~Derived()
    {
        Local0 l0;
        Local1 l1;
    }
};


int main()
{
    Derived d;

    return 0;
}

 

10 / 14

Can I kill a local object by calling the destructor before going it out of the scope (Before the close } )

11 / 14

Should I explicitly call a destructor on a local variable?

12 / 14

#include <iostream>
using namespace std; 
class A
{
    int id;
    static int count;
public:
    A() {
        count++;
        id = count;
        cout << "constructor for id " << id << endl;
    }
    ~A() {
        cout << "destructor for id " << id << endl;
    }
};
  
int A::count = 0;
  
int main() {
    A a[3];
    return 0;
}

 

1. 

constructor for id 1
constructor for id 2
constructor for id 3
destructor for id 3
destructor for id 2
destructor for id 1

2. 

constructor for id 1
constructor for id 2
constructor for id 3
destructor for id 1
destructor for id 2
destructor for id 3

3. 

Compiler Dependent.

4. 

constructor for id 1
destructor for id 1

13 / 14

What’s the order that objects in an array are destructed?

int main()
{
    Test obj[5]; //array of Test class object
        
    return 0;
}

 

14 / 14

Predict the output of following C++ progran

#include <iostream>
using namespace std;
  
int i;
  
class A
{
public:
    ~A()
    {
        i=10;
    }
};
  
int foo()
{
    i=3;
    A ob;
    return i;
}
  
int main()
{
    cout << foo() << endl;
    return 0;
}

 

Your score is

The average score is 0%

0%

Recommended Articles for you: