![]() |
#2
无诲今生2009-10-04 08:55
|

#include <iostream>
using namespace std;
int main()
{
int i=0,j=0;
int *p;
int *p1;
p=&i;
p1=&j;
*p=5;
cout<<"i "<<i<<endl;
cout<<"*p "<<*p<<endl;
cout<<"j "<<j<<endl;
cout<<"*p1 "<<*p1<<endl;
p=p1;
*p=100;
cout<<*p<<" "<<*p1<<endl;
cout<<"i "<<i<<endl;
cout<<"*p "<<*p<<endl;
cout<<"j "<<j<<endl;
cout<<"*p1 "<<*p1<<endl;
return 0;
}
using namespace std;
int main()
{
int i=0,j=0;
int *p;
int *p1;
p=&i;
p1=&j;
*p=5;
cout<<"i "<<i<<endl;
cout<<"*p "<<*p<<endl;
cout<<"j "<<j<<endl;
cout<<"*p1 "<<*p1<<endl;
p=p1;
*p=100;
cout<<*p<<" "<<*p1<<endl;
cout<<"i "<<i<<endl;
cout<<"*p "<<*p<<endl;
cout<<"j "<<j<<endl;
cout<<"*p1 "<<*p1<<endl;
return 0;
}
这段指针代码的运行结果如下
只有本站会员才能查看附件,请 登录
在两个指针没有相互赋值之前,我修改
指针*P的值的话,指针指向的&i的值会发生变化,
但为什么在指针p和指针p1在使用了p=p1;
这句话的时候指针 p所执向的i的值没有了变化?这个是为什么?