1.

Constructor of automatic variables is called ____________________(a) When execution reaches the place of declaration of automatic variables(b) When the program is compiled(c) When the execution is just started(d) Just before the execution of the programThis question was addressed to me in an interview for job.I'd like to ask this question from Automatic Variable topic in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right CHOICE is (a) When execution reaches the place of declaration of automatic variables

Best explanation: Only when the execution reaches the place where the automatic variable was DECLARED, the constructor is called. This is to ensure that the memory is not allocated if not NEEDED. The memory is allocated and then destroyed as soon as it goes out of scope.



Discussion

No Comment Found

Related InterviewSolutions