Which statement correctly describes the difference between new and malloc in C++?

Options

  • A. new invokes the appropriate constructor for an object; malloc does not invoke constructors
  • B. malloc automatically invokes every C++ constructor
  • C. new must always be paired with free
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. new invokes the appropriate constructor for an object; malloc does not invoke constructors

Detailed Explanation

Correct Answer: Option A

Explanation: In C++, new allocates memory and initializes an object, invoking its constructor when applicable. malloc allocates raw memory and does not invoke C++ constructors. Memory from new is released with delete, while memory from malloc is released with free.