A

Admin • 802.91K Points
Coach

Q. What is the output of the following C++ program?

Code:
#include<iostream>
using namespace std;

class Point {
private:
int x;
int y;
public:
Point(int a = 0, int b = 0); // Normal constructor
Point(const Point &p); // Copy Constructor
};

Point::Point(int a, int b) {
x = a;
y = b;
cout << "Normal constructor called
";
}

Point::Point(const Point &p) {
x = p.x;
y = p.y;
cout << "Copy constructor called
";
}

int main()
{
Point *p1, *p2;
p1 = new Point(5, 10);
p2 = new Point(*p1);
Point p3 = *p1;
Point p4;
p4 = p3;
return 0;
}
  • (A) Normal constructor called Copy constructor called Copy constructor called Normal constructor called
  • (B) Normal constructor called Normal constructor called Normal constructor called Copy constructor called Copy constructor called Normal constructor called
  • (C) Copy constructor called Normal constructor called Copy constructor called Copy constructor called Normal constructor called
  • (D) None of the above
  • Correct Answer - Option(A)
  • Views: 2
  • Filed under category C++
  • Hashtags:

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.