Answers for "how to delete pointer c++"

C++
3

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
Posted by: Guest on February-25-2021

Browse Popular Code Answers by Language