returning address of local variable or temporary
A function returns the address of a local variable or temporary object. Local variables and temporary objects are destroyed when a function returns, so the address returned is not valid. The following sample generates C4172:
int *func1() { int test = 1; return &test; // C4172 } /* use the following definition of func1 to resolve the warning int *func1() { int test = 1; int* testptr = &test; return testptr; } */ void main() { }