+ 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

3rd Jan 2018, 2:38 PM
Piotr
Piotr - avatar
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.
4th Jan 2018, 4:57 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 5
not in Sololearn bug for sure, probably is your mistake somewhere...
3rd Jan 2018, 5:43 PM
Vukan
Vukan - avatar
+ 3
Where???
3rd Jan 2018, 5:44 PM
Piotr
Piotr - avatar