Doubt in concept "Returning Local Arrays vs Dynamic Arrays"

Hi, I have a doubt regarding this concept.
Sir told us that returning a local variable from a function is forbidden, because when the function’s scope finishes, the local variable which we are returning, may get destroyed. So it can show us segmentation fault or some garbage value. My question is that in questions of recursion or any other type, we usually create a local variable inside a function and return its value in the main. For eg in Fibonacci ques, we create a bucket sum and do an operation on it, and then return it. So how come that thing is working?

hi @Vinayak-Bhardwaj whats returned will be available, like here address is returned so u will get the address but the content wont be accessible

Thank you for the explaination!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.