pear = new char[1024]; pear = "happy go lucky"; delete [] pear; // exception
pear = new char[1024];
1024个字符的内存从堆和梨点分配到它的开头.
pear = "happy go lucky";
pear现在指向驻留在只读段中的字符串文字,并且先前分配的内存被泄露.
delete [] pear;
您尝试释放只读字符串,这是一种未定义的行为,表现为运行时异常.