Home » Aptitude Questions and Answers » C++ Aptitude Questions and Answers

C++ constructor, destructor aptitude questions and answers (set 2)

C++ constructor and destructor questions: This section contains aptitude questions and answers (MCQs) on Constructors and Destructors in C++.
Submitted by IncludeHelp, on May 03, 2019

List of C++ Constructor and Destructor Aptitude Questions & Answers

1) Constructor(s) which is/are added automatically with a class, if we do not create our own constructor?

  1. Default Constructor
  2. Copy Constructor
  3. Both default and copy constructors
  4. None

2) Does assignment operator implement automatically with the class?

  1. Yes
  2. No

3) What will be the output of the following code?

#include<iostream>
using namespace std;

//class definition
class Example {
    Example() { 
        cout << "Constructor called"; 
    }
};
 
//main() code 
int main()
{
   Example Ex;
   return 0;
}
  1. Constructor called
  2. Program successfully executed – no output
  3. Compile time error
  4. Run time error

4) What will be the output of the following code?

#include<iostream>
using namespace std;

//class definition
class Example {
    public:
    Example() { 
        cout << "Constructor called "; 
    }
};
 
//main() code 
int main()
{
   Example Ex1, Ex2;
   return 0;
}
  1. Constructor called
  2. Constructor called Constructor called
  3. Compile time error
  4. Run time error

5) What will be the output of the following code?

#include<iostream>
using namespace std;

//class definition
class Example {
    public:
        int a;
        int b;
};
 
//main() code 
int main()
{
   Example Ex1  = {10, 20};
   cout << "a = " << Ex1.a <<", b = " << Ex1.b;
   return 0;
}
  1. Compile time error
  2. Run time error
  3. a = 10, b = 20
  4. a = 10, b = 10






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.