Chapter 9: Problem 10
Under what circumstances can you successfully return a pointer from a function?
Short Answer
Expert verified
Answer: Returning a pointer from a function can be successful and safe when the memory to which the pointer points remains accessible and valid after the function call. This can be achieved by returning pointers to dynamically allocated memory (using malloc or calloc), global variables, or static variables, but caution is advised regarding reentrancy and possible side effects. It is important to avoid returning pointers to local variables, as their memory is deallocated once the function scope ends.