1.

Which is the correct syntax for returning an object by value?(a) void functionName ( ){ }(b) object functionName( ) { }(c) class object functionName( ) { }(d) ClassName functionName ( ){ }The question was posed to me during an interview for a job.My doubt stems from Returning Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» CORRECT option is (d) CLASSNAME functionName ( ){ }

EASY explanation - The class NAME itself should be the return type of the function. This NOTIFIES that the function will return an object of specified class type. Only the class name should be specified.


Discussion

No Comment Found

Related InterviewSolutions