c++ delete uninitialized pointer code example
Example: how to delete pointer c++
int* ptr; // pointer declaration
ptr = new int; // dynamically allocate an integer on heap
delete ptr; // deletes integer from heap & frees memory
ptr = nullptr; // always good to reset pointer
ptr = new int[5]; // dynamically allocate integer array on heap with size 5
delete[] ptr; // deletes integer array from heap & frees memory
ptr = nullptr; // always good to reset pointer