なぜ出力がそのようなものになるのか誰が知っていますか?
そのようなポインターを使用するのは間違っていますが、なぜそのように動作するのかを理解したいと思います。
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;
}