1.

In C++, if new operator is used, when is the constructor called?(a) Before the allocation of memory(b) After the allocation of memory(c) Constructor is called to allocate memory(d) Depends on codeI had been asked this question by my school teacher while I was bunking the class.Asked question is from New Operator in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct choice is (b) After the allocation of memory

Explanation: The constructor function is called after the allocation of memory. In C++ the feature works in a bit DIFFERENT way. The memory for all the data MEMBERS is allocated first and then the constructor function is called to finalize the memory allocated.



Discussion

No Comment Found

Related InterviewSolutions