I tried the code in the lecture, GAVE SEGMENTATION FAULT!

I thought segmentation fault is coming due to memory leak so i modified the code a bit:

Still giving the segmentation fault, Sharing my code with you using CB IDE, Please clear:

Mistakes

  1. main the mistake you have done is while printing the character array

to Print character array correct statement is
cout<<ptr<<endl;
cout<<*ptr<<endl: :negative_squared_cross_mark:
it will print only first character of array
and when ptr is null it will give run errror

  1. you have to delete output only when output exist
    if it doesn’t exist then it will give run error
    so put a condition on it

see the modified code below

Modified Code

if you want to ask something about this feel free to ask
i hope this helps
if yes show your response with :heart: and don’t forgot to mark doubt as resolved

Thank you so much
Understood your point
:heart: