Первый вариант неправильный и вызовет неопределённое поведение во время выполнения программы (порча кучи и падение программы - наиболее вероятный исход), второй - правильный. Правило простое: каждому new должен соответствовать delete, а каждому new [] - delete [].
В стандарте (5.3.5/2) чётко сказано (выделение жирным - моё):
Цитата | In the first alternative (delete object), the value of the operand of delete may be a null pointer value, a pointer to a non-array object created by a previous new-expression, or a pointer to a subobject (1.8) representing a base class of such an object (Clause 10). If not, the behavior is undefined. In the second alternative (delete array), the value of the operand of delete may be a null pointer value or a pointer value that resulted from a previous array new-expression. If not, the behavior is undefined.
|
|