You are absolutely correct at this point of pointer to local variable.
the pointer to a local variable will keep pointing to the memory that will has gone out of scope.
The reason this might be working is by pure chance, the memory that the returned pointer is pointing has still not got anything else overwritten on it(since nothing is written on stack still) and thus it is working. If you keep this code in the middle of more code then it will definitely give incorrect results and it might even crash.
try this for instance
int * ret()
{
int a = 10;
return &a;
}
int _tmain(int argc, _TCHAR* argv[])
{
int *i = ret();
string s = "some rando, string to test";
cout<<*i;
return 0;
}