Is delete[] equal to delete?

前端 未结 6 1592
-上瘾入骨i
-上瘾入骨i 2020-11-22 01:05
IP_ADAPTER_INFO *ptr=new IP_ADAPTER_INFO[100];

if I free using

delete ptr;

will it lead to memory leak, if not t

6条回答
  •  死守一世寂寞
    2020-11-22 01:43

    Using delete operator on allocations with new T[n] is undefined and will vary from compiler to compiler. AFAIK, MSVC compiler for example will produce different code than GCC.

    If A points to an array that was allocated via new T[n], then you must delete it via delete[] A. The difference between delete and delete[] is straightforward - the former destroys a scalar object and the latter destroys an array.

提交回复
热议问题