C++ | Constructors | Question 5
Output of following program?
#include<iostream> using namespace std; class Point { public: Point() { cout << "Normal Constructor called\n"; } Point(const Point &t;) { cout << "Copy constructor called\n"; } }; int main() { Point *t1, *t2; t1 = new Point(); t2 = new Point(*t1); Point t3 = *t1; Point t4; t4 = t3; return 0; } |
chevron_right
filter_none
(A) Normal Constructor called
Normal Constructor called
Normal Constructor called
Copy Constructor called
Copy Constructor called
Normal Constructor called
Copy Constructor called
(B) Normal Constructor called
Copy Constructor called
Copy Constructor called
Normal Constructor called
Copy Constructor called
(C) Normal Constructor called
Copy Constructor called
Copy Constructor called
Normal Constructor called
Answer: (C)
Explanation: See following comments for explanation:
Point *t1, *t2; // No constructor call t1 = new Point(10, 15); // Normal constructor call t2 = new Point(*t1); // Copy constructor call Point t3 = *t1; // Copy Constructor call Point t4; // Normal Constructor call t4 = t3; // Assignment operator call
Recommended Posts:
- C++ | Constructors | Question 15
- C++ | Constructors | Question 3
- C++ | Constructors | Question 6
- C++ | Constructors | Question 10
- C++ | Constructors | Question 17
- C++ | Constructors | Question 1
- C++ | Constructors | Question 16
- C++ | Constructors | Question 2
- C++ | Constructors | Question 14
- C++ | Constructors | Question 4
- C++ | Constructors | Question 7
- C++ | Constructors | Question 8
- C++ | Constructors | Question 17
- C++ | Constructors | Question 12
- C++ | Constructors | Question 13



