Answer:
Hi Hannahdavy! This is a good question. The problem lies in this part of the program:
p2 = p1;
Explanation:
In C/C++, memory is manually managed. When the variable p1 is assigned to variable p2, the memory allocated for p1 is left unmanaged, causing memory issues. Therefore the program will throw a “double free or corruption (fasttop)” error. What is needed to resolve the issue is to either (a) assign a null value to p1 after p1 has been assigned to p2, or (b) remove the p2 assignment of p1, depending of what the function is actually trying to do in the program.