1.

If an object is declared in a user defined function __________________(a) Its memory is allocated in stack(b) Its memory is allocated in heap(c) Its memory is allocated in HDD(d) Its memory is allocated in cacheThe question was posed to me in a national level competition.I'm obligated to ask this question of Memory Allocation of Object in section Object of Object Oriented Programming

Answer»

The correct option is (a) Its memory is allocated in stack

The best I can explain: The memory for any DATA or object that are used in a user defined FUNCTION are always allocated in the stack. This is to ensure that the object is destroyed as soon as the function is RETURNED. Also this ENSURES that the correct memory allocation and DESTRUCTION is performed.



Discussion

No Comment Found

Related InterviewSolutions