delete pointer
📝 C++Deletes a dynamically allocated object to prevent memory leaks and free its resources.
C++
int ptr = new int(42);
delete ptr;
ptr = nullptr;
Deletes a dynamically allocated object to prevent memory leaks and free its resources.
int ptr = new int(42);
delete ptr;
ptr = nullptr;
Comments
@samuel just to clarify, that delete only works if the pointer was allocated with new, using malloc or new[] would need free or delete[] instead.