Memory for Functions

What if we want to create something in a function? • We often want to run functions that create data • But a function’s variable are destroyed when it returns • So this will not work: // Make an array and try to return its address int *create_array(void) { int primes[5] = {2,3,5,7,11}; return primes; } // It returns a pointer to a variable that no longer exists // The function has returned and no longer has that memory. // This is very dangerous if another function has that memory.