Actually this was a homework I got. But I do not know the answer. Can anyone please help me?
What is the important memory allocation flaw that is seen in the following C++ code? How can you avoid it?
void testFunction(){
int * p = new int(5);
cout << p << *p << &p << endl;
}
The memory is never released, so you have a memory leak. You can fix this by deleting the pointer: