InterviewSolution
Saved Bookmarks
| 1. |
Is the destruction of temporary object safe (while returning object)?(a) Yes, the resources get free to use(b) Yes, other objects can use the memory space(c) No, unexpected side effects may occur(d) No, always gives rise to exceptionsThis question was posed to me in an interview for job.Question is from Passing and Returning Object with Functions in section Object of Object Oriented Programming |
|
Answer» CORRECT choice is (c) No, unexpected side EFFECTS MAY occur Best explanation: The destruction of temporary variable may GIVE rise to unexpected logical errors. Consider the destructor which may free the dynamically allocated memory. But this may abort the program if another is still trying to copy the values from that dynamic memory. |
|