in this question our output pointer is changing every time in different cycles and it is a dynamic allocation so why are we not first deallocating the output ponter every time to prevent memory leakage.
Query regarding output pointer in it
If i am doing that then it is saying that output is not declared in this scope.
Here is my code
Can you please make the changes in it
u need to do delete by using ptr pointer.
delete ptr.
but it will create one issue i.e we are using ptr later in our while loop condition.
so i would suggest to not delete it.
if u want then u boolean variable to check for null.
So it means that sometimes in some cases memory leakage can’t be avoided
for this problem we can avoid .