Junior
What are the two types of delete operators in C++?
sobes.tech AI
Answer from AI
The first type is delete for deleting a single object. It calls the object's destructor (if it exists) and frees the memory allocated for the object.
The second type is delete[] for deleting a dynamic array of objects. It sequentially calls destructors for each element of the array and then frees the memory block allocated for the array.
Example:
// Deleting a single object
MyClass* obj = new MyClass();
// ...
delete obj;
// Deleting a dynamic array
MyClass* arr = new MyClass[10];
// ...
delete[] arr;