1.

If the object is passed by value to a copy constructor?(a) Only public members will be accessible to be copied(b) That will work normally(c) Compiler will give out of memory error(d) Data stored in data members won’t be accessibleI have been asked this question in quiz.My doubt is from Constructors topic in section Constructors and Destructors of Object Oriented Programming

Answer»

The CORRECT choice is (c) Compiler will give out of memory error

The explanation is: Compiler runs out of memory. This is because while PASSING the argument by VALUE, a constructor of the OBJECT will be called. That in turn called another object constructor for values, and this GOES on. This is like a constructor call to itself, and this goes on infinite times, hence it must be passed by reference, so that the constructor is not called.



Discussion

No Comment Found

Related InterviewSolutions