M
M
Maxim Korytko2020-02-10 20:55:00
C++ / C#
Maxim Korytko, 2020-02-10 20:55:00

Do the records have the same result?

...
...
int main(){
int length = 5;
char* arr = new char[length]
.
.
.
delete[] arr;
}
////////////////////////////////////////////////////////////////////////
int main(){
int length = 5;
char* arr = new char[length]
.
.
.
 arr = nullptr;


Will the din area be cleared. memory, if the pointer to the first element is assigned nullptr?
Or will the memory be cleared only with the delete operator?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sumor, 2020-02-10
@Sumor

Anything created with new must be deleted with delete.

1
15432, 2020-02-10
@15432

The memory will be cleared only through delete, in the second case we will get a leak

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question