首页 > C++编程 > delete与delete[]

delete与delete[]

delete and delete with brackets

Let's look at a block of code as follows at first.

#include <iostream>   
using namespace std;   
   
class Test   
{   
public:   
    ~Test()   
    {   
        puts("Test::~Test");   
    }   
};   
int main()   
{   
    Test* pT = new Test[10];   
    char* pz = new char[10];   
    //delete operation   
}   

 Which of the folloing choice will lead to memory leak? (There may be one or more choices for this problem)

A : delete pz;
B : delete[] pz;
C : delete pT;
D : delete[] pT;

The answer is C. The delete operator is equals to the delete[] operater when the object is a built-in style object.


觉得文章还不错?点击此处对作者进行打赏!


本文地址: 程序人生 >> delete与delete[]
作者:代码疯子(Wins0n) 本站内容如无声明均属原创,转载请保留作者信息与原文链接,谢谢!


更多



分类: C++编程 标签: ,
  1. segFault
    2014年8月23日03:04 | #1

    Disagree.

    it is an /*undefined behavior*/ when you dealloc an array without putting the brackets.

    [回复]

  1. 本文目前尚无任何 trackbacks 和 pingbacks.