Why is returning a pointer to a local variable invalid, and what are safer alternatives?
An ordinary local variable with automatic storage duration ceases to exist when the function returns. A pointer to it then dangles, and accessing the former object through that pointer is invalid even...