C++ 中的 delete vs delete[] 运算符

2022-01-30 00:00:00 memory-management c++ delete-operator

What is the difference between delete and delete[] operators in C++?

解决方案

The delete operator deallocates memory and calls the destructor for a single object created with new.

The delete [] operator deallocates memory and calls destructors for an array of objects created with new [].

Using delete on a pointer returned by new [] or delete [] on a pointer returned by new results in undefined behavior.

相关文章