Who knows why the output is such?
Although it's wrong to use a pointer like that, I would still like to understand why it behaves the way it does.
int* foo()
{
int a=9;
int *p=&a;
//definitely not right to return a pointer to an invalid varible
return p;
}
int main(int argc, char* argv[])
{
int *p=foo();
cout<<*p<<endl;//9
cout<<*p<<endl;//2357228
*p=2;
cout<<*p<<endl;//2
(*p)++;
cout<<*p<<endl;//2357229
cout<<*p<<endl;//2357228
cout<<*p<<endl;//2357228
(*p)++;
cout<<*p<<endl;//2357229
cout<<*p<<endl;//2357228
return 0;
}