why there is necessity of copy constructor in a class?
Copy constructor
@aman17nov1999 we need a copy constructor, to well, copy objects. It is used to initialize objects of same class. But the default copy constructor makes a shallow copy. It doesn’t matter much if you are using simple variables like int or char. But suppose you have a pointer data member, and a shallow copy gets made for the pointer, then any changes made by any of those 2 objects will reflect directly on the pointer address. To avoid that, we need a deep copy, so that a separate memory location is provided to the new pointer. You can read more about it here https://www.geeksforgeeks.org/copy-constructor-in-cpp/