Skip to content
Related Articles

Related Articles

Improve Article

C++ | Constructors | Question 9

  • Last Updated : 28 Jun, 2021

Predict the output of following program.

using namespace std;
class Test
   { cout << "Constructor called"; }
int main()
    Test *t = (Test *) malloc(sizeof(Test));
    return 0;

(A) Constructor called
(B) Empty
(C) Compiler Error
(D) Runtime error

Answer: (B)

Explanation: Unlike new, malloc() doesn’t call constructor (See this)

If we replace malloc() with new, the constructor is called, see this.

Quiz of this Question

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :