What happens when a pointer to a local variable is returned by a function?
Undefined behaviour. Anything can happen. The compiler will give you a warning.
This is g++
warning for that mistake:
g++ -Wall -std=c++11 -O3 test.cpp -o test
warning: function returns address of local variable [-Wreturn-local-addr]