A
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;
}
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;
}
- Correct Answer - Option(A)
- Views: 2
- Filed under category C++
- Hashtags:
Discusssion
Login to discuss.