GoConqr has a new look! Let us know what you think.

Quiz

Constructors

PathaPadha Support 10 questions

Take the quiz

This quiz has a time limit, so it opens in the usual player.

Questions in this quiz (10)

  1. 1Which of the followings is/are automatically added to every class, if we do not write our own.
    1. ACopy Constructor
    2. BAssignment Operator
    3. CA constructor without any parameter
    4. DAll of the above
  2. 2When a copy constructor may be called?
    1. AWhen an object of the class is returned by value.
    2. BWhen an object of the class is passed (to a function) by value as an argument.
    3. CWhen an object is constructed based on another object of the same class
    4. DWhen compiler generates a temporary object.
    5. EAll of the above
  3. 3Output of following program?
    #include<iostream>
    using namespace std;
    class Point {
    Point() { cout << "Constructor called"; }
    };

    int main()
    {
    Point t1;
    return 0;
    }
    1. ACompiler Error
    2. BRuntime Error
    3. CConstructor called
  4. 4#include<iostream>
    using namespace std;
    class Point {
    public:
    Point() { cout << "Constructor called"; }
    };

    int main()
    {
    Point t1, *t2;
    return 0;
    }
    1. ACompiler Error
    2. BConstructor called
      Constructor called
    3. CConstructor called
  5. 5Output 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. ANormal Constructor called
      Normal Constructor called

      Normal Constructor called

      Copy Constructor called

      Copy Constructor called

      Normal Constructor called

      Copy Constructor called
    2. BCopy Constructor called

      Normal Constructor called

      Copy Constructor called
      Normal Constructor called
      Copy Constructor called
    3. CNormal Constructor called
      Copy Constructor called

      Copy Constructor called

      Normal Constructor called
  6. 6#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;
    }
    1. A10 10
    2. B10 0
    3. C10 followed by Garbage Value
    4. DCompiler Error
  7. 7What 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;
    }
    1. ACompiler Error
    2. Bx = 0 y = 0
    3. Cx = garbage value y = garbage value
  8. 8#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;
    }
    1. Ax = 0 y = 0
    2. BCompiler Error
    3. Cx = garbage value y = garbage value
  9. 9Predict 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;
    }
    1. AConstructor called
    2. BEmpty
    3. CCompiler Error
    4. DRuntime error
  10. 10#include <iostream>
    using namespace std;

    class Test
    {
    public:
    Test() { cout << "Hello from Test() "; }
    } a;

    int main()
    {
    cout << "Main Started ";
    return 0;
    }
    1. AHello from Test() Main Started
    2. BCompiler Error: Global objects are not allowed
    3. CMain Started Hello from Test()
    4. DMain Started

Information

Description
C++ Quiz on Constructors, created by PathaPadha Support on 27/10/2020.
Language
English
Views
60
Tags
c++
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?