Which of the following is correct about new and malloc?

a) Both are available in C
b) Pointer object initialization of a class with both new and malloc calls the constructor of that class
c) Pointer object initialization of a class using new involves constructor call whereas using malloc does not involve constructor call
d) Pointer object initialization of a class using malloc involves constructor call whereas using new does not involve constructor call

1 thought on “Which of the following is correct about new and malloc?”

  1. c
    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.

Leave a Comment