1.

If an object is declared inside the function then ____________________ outside the function.(a) It can be returned by reference(b) It can’t be returned by reference(c) It can be returned by address(d) It can’t be returned at allThe question was asked in a job interview.Origin of the question is Returning Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct OPTION is (b) It can’t be returned by REFERENCE

Explanation: The object which is declared inside the class can never be returned by reference. This is because the object will be destroyed as it goes out of SCOPE when the function is returned. The local variables get destroyed when function is returned HENCE the local objects can’t be returned by reference.



Discussion

No Comment Found

Related InterviewSolutions