+ 4
Where I made a mistake ?
Why my program deletes only some of the elements of the array? https://code.sololearn.com/cuXVndu4X8vU/?ref=app
3 Respuestas
+ 3
Its not that the program deletes some values. It does delete all values, but the values shown are random, as the compiler has deallocated the memory, but the assignment of the nullptr to the elements is purely random, and unpredictable.
The delete operation actually never removes the memory, it just marks it available for use by any other new operation. Thus, after deletion, assignment of the nullptr to the elements is random. You may check this by doing:
int * a; cout<<*a;
// you may get a number instead of a
// blank value, though no memory has
// been allocated for a.
Now, to delete all elements after the operation, simply do :
variable = nullptr;
And this erases the array completely.
+ 5
not in Sololearn bug for sure, probably is your mistake somewhere...
+ 3
Where???