Dynamic allocation or return by value. Former returns a pointer to allocated memory (and you have to handle deallocation appropriately. Latter .. you essentially declare a variable in the main for the return value.
Third option: declare in main and pass to function by reference or by pointer.
Lets say I have a function with a while loop that adds 1 to x as long as x is less than 5. Now that x has the value of 5 I want to be able to use x in my main function. X is declared in my function but I want to use it in an if statement in main.