Is delete[] equal to delete?

前端 未结 6 1581
-上瘾入骨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:33

    Whether this leads to a memory leak, wipes your hard disk, gets you pregnant, makes nasty Nasal Demons chasing you around your apartment, or lets everything work fine with no apparent problems, is undefined. It might be this way with one compiler, and change with another, change with a new compiler version, with each new compilation, with the moon phases, your mood, or depending on the number of neutrinos that passed through the processor on the last sunny afternoon. Or it might not.

    All that, and an infinite number of other possibilities are put into one term: Undefined behavior:

    Just stay away from it.

提交回复
热议问题