Today I have been facing a problem that I have had before. I learnt the next things:
- when you declare an array as a local variable within a function in C, the memory for that array is automatically deallocated when the function exits. This is because local variables are allocated on the stack, and the memory allocated for the stack frame of a function is automatically reclaimed when the function returns
- You should use
malloc()
or a similar function. And then be sure to free the memory.