Implementing string tokenizer

why there is a need to create array dynamically here?
each time function is called it creates a memory in the heap,
and here each time we have to return a token which could be done without creating dynamic array.

After a function returns, all the memory allocated to it is de-allocated, so if you declare a local “output” char array and return it, when the function returns, the local char array will be destructed, and the pointer will be useless, and you wont be able to access the token from “main” anymore.

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.