1.

It’s necessary to pass object by reference in copy constructor because ____________(a) Constructor is not called in pass by reference(b) Constructor is called in pass by reference only(c) It passes the address of new constructor to be created(d) It passes the address of new object to be createdI have been asked this question in an online quiz.My question comes from Types of Constructors topic in chapter Constructors and Destructors of Object Oriented Programming

Answer»

The correct option is (a) CONSTRUCTOR is not called in pass by reference

For explanation: Object must be passed by reference to copy constructor because constructor is not called in pass by reference. Otherwise, in pass by VALUE, a temporary object will be created which in turn will try to call its constructor that is ALREADY being used. This results in CREATING infinite NUMBER of objects and hence memory shortage error will be shown.



Discussion

No Comment Found

Related InterviewSolutions