Microsoft Interview Question

Phone interview question: In C, why is it considered bad form for a function to return a pointer to a stack-allocated variable? What happens if you do it anyway?

Interview Answer

Anonymous

May 5, 2009

Here's a hint: You can actually do this in C, and your program will work okay... for a while. The data that your pointer points to will not be corrupted until your program performs a certain action.

1