1.

Constructor function is not called when an object is passed to a function, will its destructor be called when its copy is destroyed?(a) Yes, depending on code(b) Yes, must be called(c) No, since no constructor was called(d) No, since same object gets usedThe question was posed to me in an international level competition.I would like to ask this question from Passing and Returning Object with Functions topic in portion Object of Object Oriented Programming

Answer»

Correct option is (b) Yes, MUST be called

To explain: EVEN THOUGH the constructor is not called when the object is passed to a FUNCTION, the copy of the object is still created, where the values of the members are same. When the object have to be destroyed, the destructor is called to free the MEMORY and resources that the object might have reserved.



Discussion

No Comment Found

Related InterviewSolutions