c++ - What is the important memory allocation flaw that is seen here? -


Actually it was a homework that I found. But I do not know the answer. Can somebody help me out?

Important Memory Allocation Defects What is seen in the following C ++ code? How can you avoid it?

  Zero test function () {int * p = new int (5); Cout & lt; & Lt; P & LT; & Lt; * P & LT; & Lt; & Amp; P & lt; & Lt; Endl; }   

Memory is never released, so you have a memory leak You can correct it by removing:

  Zero testing function () {int * p = new int (5); Cout & lt; & Lt; P & LT; & Lt; * P & LT; & Lt; & Amp; P & lt; & Lt; Endl; Remove p; }    

Comments