Google News
logo
CPP - Quiz(MCQ)
Which of the following is correct about new and malloc?
A)
Both are available in C
B)
Pointer object initialization of a class using new involves constructor call whereas using malloc does not involve constructor call
C)
Pointer object initialization of a class with both new and malloc calls the constructor of that class
D)
Pointer object initialization of a class using malloc involves constructor call whereas using new does not involve constructor call

Correct Answer :   Pointer object initialization of a class using new involves constructor call whereas using malloc does not involve constructor call


Explanation : Object initialization using new keyword involves constructor call whereas malloc does not involve constructor call. That’s why new is explicitly added in C++. Also, malloc is used to assign memory to any pointer hence it assigns memory equals to the size of the class however new keyword involves initialization also hence calls the constructor of that class.

Advertisement