Query regarding output pointer in it

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.

hello @Parmeet-Kalsi-1631789033630118
yeah u can do that after printing output.

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 .