If you want to return pointers to memory, then that memory has to exist after the function call ends. (The only other method to do that, other than malloc, is to maintain a static array and return a pointer to that. However, in that case, you only have one chunk of memory no matter how often you call the function -- that is, calling the function again will reuse the same memory, not get you more memory.)