[Solved] Why should a function not return a local array? [duplicate]


s is a local variable that only exists within the function.

Once the function exits, s no longer exists, and its memory will be re-allocated to other parts of your program.

Therefore, your function is returning a pointer to a random meaningless block of memory.

2

solved Why should a function not return a local array? [duplicate]