ProgrammingHardProduct-company placement · C++

How many of these statements about C++ dynamic memory are correct? (i) Memory obtained with new[] must be released with delete[]. (ii) Applying delete to a null pointer does nothing. (iii) Memory obtained with malloc may be released with delete. (iv) Plain new reports allocation failure by throwing std::bad_alloc.

  1. A. 2
  2. B. 4
  3. C. 3
  4. D. 1

Correct answer: C. 3

(i), (ii) and (iv) are correct. (iii) is undefined behaviour: malloc pairs with free and new with delete; delete also runs a destructor that malloc never constructed.

More OOP with C++ and Java questions

Exams that ask this topic