Possible Duplicate:
Can a local variable's memory be accessed outside its scope?
Returning the address of a variable inside a function is bad because that variable will no longer exist if the stack frame where the variable belongs end.
So why this code works fine
int* test(){
int a = 11;
return &a;
}
int main(){
int *a;
a = test();
cout << *a;
return 0;
}