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

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

Our C++ constructor quiz (C++ constructor multiple Choice Questions ) focuses on all areas of the C++ constructor and its concept. We will regularly update the MCQ on the C++ constructor 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 constructor in C++:

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

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

1 votes, 5 avg

You have 30 minutes to take the MCQs on Constructor in C++

Your time has been Over.


MCQ on constructor in C++

C++ MCQ

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

1 / 21

#include<iostream>
using namespace std;
class Point {
public:
    Point() { cout << "Constructor called"; }
};
 
int main()
{
   Point t1, *t2;
   return 0;
}

 

2 / 21

Output of following program?

#include<iostream>
using namespace std;
 
class Point {
public:
    Point() { cout << "Normal Constructor calledn"; }
    Point(const Point &t) { cout << "Copy constructor calledn"; }
};
 
int main()
{
   Point *t1, *t2;
   t1 = new Point();
   t2 = new Point(*t1);
   Point t3 = *t1;
   Point t4;
   t4 = t3;
   return 0;
}

 

1.

Normal Constructor called
Normal Constructor called

Normal Constructor called

Copy Constructor called

Copy Constructor called

Normal Constructor called

Copy Constructor called

 

2.

Normal Constructor called
Copy Constructor called

Copy Constructor called

Normal Constructor called

Copy Constructor called

 

 

3.

Normal Constructor called
Copy Constructor called

Copy Constructor called

Normal Constructor called

 

 

 

3 / 21

#include<iostream>
using namespace std;
  
class Test
{
public:
  Test();
};
  
Test::Test()  {
    cout << " Constructor Called. ";
}
  
void fun() {
  static Test t1;
}
  
int main() {
    cout << " Before fun() called. ";
    fun();
    fun();
    cout << " After fun() called. ";  
    return 0;
}

 

4 / 21

Predict the output of following program.

#include<iostream>
#include<stdlib.h>
using namespace std;
 
class Test
{
public:
   Test()
   { cout << "Constructor called"; }
};
 
int main()
{
    Test *t = (Test *) malloc(sizeof(Test));
    return 0;
}

 

5 / 21

#include <iostream>
using namespace std;
 
class Point
{
    int x, y;
public:
   Point(int i = 0, int j = 0) { x = i; y = j; }
   int getX() { return x; }
   int getY() { return y; }
};
 
int main()
{
    Point p1;
    Point p2 = p1;
    cout << "x = " << p2.getX() << " y = " << p2.getY();
    return 0;
}

 

6 / 21

What is the output of following program?

#include <iostream>
using namespace std;
 
class Point
{
    int x, y;
public:
   Point(const Point &p) { x = p.x; y = p.y; }
   int getX() { return x; }
   int getY() { return y; }
};
 
int main()
{
    Point p1;
    Point p2 = p1;
    cout << "x = " << p2.getX() << " y = " << p2.getY();
    return 0;
}

 

7 / 21

Which of the followings is/are automatically added to every class, if we do not write our own.

8 / 21

#include<iostream>
using namespace std;
 
class X 
{
public:
    int x;
};
 
int main()
{
    X a = {10};
    X b = a;
    cout << a.x << " " << b.x;
    return 0;
}

 

9 / 21

Predict the output of following program.

#include<iostream>
using namespace std;
class Point {
    int x;
public:
    Point(int x) { this->x = x; }
    Point(const Point p) { x = p.x;}
    int getX() { return x; }
};
 
int main()
{
   Point p1(10);
   Point p2 = p1;
   cout << p2.getX();
   return 0;
}

 

10 / 21

#include<iostream>
using namespace std;
 
class Test
{
public:
   Test(Test &t) { }
   Test()        { }
};
 
Test fun()
{
    cout << "fun() Calledn";
    Test t;
    return t;
}
 
int main()
{
    Test t1;
    Test t2 = fun();
    return 0;
}

 

11 / 21

Given the programming constructs i)assignment ii)for loops where the loop parameter cannot be changed within the loop iii)if-then-else iv)forward go to v)arbitrary go to vi)non-recursive procedure call vii)recursive procedure/function call viii)repeat loop, which constructs will you not include in a programming language such that it should be possible to program the terminates (i.e. halting) function in the same programming language.

12 / 21

What is the right way to declare a copy constructor of a class if the name of the class is MyClass?

13 / 21

Output?

#include<iostream>
#include<string.h>
using namespace std;
 
class String
{
    char *str;
public:
     String(const char *s);
     void change(int index, char c) { str[index] = c; }
     char *get() { return str; }
};
 
String::String(const char *s)
{
    int l = strlen(s);
    str = new char[l+1];
    strcpy(str, s);
}
 
int main()
{
   String s1("geeksQuiz");
   String s2 = s1;
   s1.change(0, 'G');
   cout << s1.get() << " ";
   cout << s2.get();
}

 

14 / 21

Predict the output of following program?

#include <iostream>
using namespace std;
class Test
{
private:
    int x;
public:
    Test(int i)
    {
        x = i;
        cout << "Called" << endl;
    }
};
 
int main()
{
    Test t(20);
    t = 30; // conversion constructor is called here.
    return 0;
}

 

15 / 21

We must use initializer list in a constructor when

16 / 21

Implicit return type of a class constructor is:

17 / 21

#include <iostream>
using namespace std;
 
class Test
{
public:
      Test() { cout << "Hello from Test() "; }
} a;
 
int main()
{
    cout << "Main Started ";
    return 0;
}

 

18 / 21

Output of following program?

#include<iostream>
using namespace std;
class Point {
    Point() { cout << "Constructor called"; }
};
 
int main()
{
   Point t1;
   return 0;
}

 

19 / 21

When a copy constructor may be called?

 

20 / 21

Constructors have _____ return type.

21 / 21

Which of the following is true about constructors. 1) They cannot be virtual. 2) They cannot be private. 3) They are automatically called by new operator.

Your score is

The average score is 0%

0%

Recommended Articles for you:

Leave a Reply

Your email address will not be published. Required fields are marked *