琢磨不透的指针丢失,不可思议
//不可思议,下面指针j怎么在地址无效的情况下又指到函数内部去了,什么原因???
#include "stdafx.h"
#include <IOSTREAM>
using namespace std;
void f1( int *& j)
{
int l=20;
int *k=&l;
j=k;
k=0;
}
void any_function_use_local_variables0()
{
int v,x;
cout<<"f0=v="<<v<<endl;
v=110;
x=102;
cout<<"f0=v="<<v<<endl;
}
void any_function_use_local_variables()
{
int a,b,c;
cout<<"f=a="<<a<<endl;
a=b=c=120;
cout<<"f=b="<<b<<endl;
}
int main()
{
int i=10;
int *j=&i;
f1(j);
cout<<*j<<endl; //20
int i4;
int i2=99;
any_function_use_local_variables();
cout<<"1 *j="<<*j<<endl; //120
cout<<"1 j="<<j<<endl; //120
any_function_use_local_variables0();
int i3=98;
cout<<"2 *j="<<*j<<endl; //120
cout<<"2 j="<<j<<endl; //120
return 0;
}