In C++, which of the following statements correctly returns the memory from…
2017
In C++, which of the following statements correctly returns the memory from the dynamic array pointer pp to the free store?
- A.
delete pp;
- B.
delete pp [ ];
- C.
delete [ ] pp;
- D.
*delete pp;
Attempted by 225 students.
Show answer & explanation
Correct answer: C
Key point: Always match allocation and deallocation: use delete for memory allocated with new, and delete[] for memory allocated with new[]. Correct syntax for freeing a dynamic array is delete[] pp;. Example: int* pp = new int[10]; delete[] pp;
A video solution is available for this question — log in and enroll to watch it.