point(指针)

 1 /*************************************************************************
 2     > File Name: change.cpp
 3     > Author:sunshunzhong
 4     > Mail:13115543132@163.com 
 5     > Created Time: 2016年05月23日 星期一 15时39分33秒
 6  ************************************************************************/
 7 
 8 #include<iostream>
 9 using namespace std;
10 int main()
11 {
12     int a=5,b=6;
13     int *p1,*p2,p;
14     p1=&a;  
15     p2=&b;
17     cout<<"p2 "<<*p2<<endl;
19     b=*p1; 
20     cout<<"b:"<<b<<endl;
21     a=*p2;
22     cout<<"a:"<<a<<endl;
23     cout<<"p1:"<<*p1<<endl;
24     cout<<"p2:"<<*p2<<endl;
25     cout<<" a , b "<<a<<" "<<b<<endl;
26     return 0;
27 
28 }

p1 只是指向a的地址,,p2 指向b 的地址, b=*p1,p2指向b的地址里面,b的值发生了改变,最终a 的又变成5

 1 /*************************************************************************
 2     > File Name: change.cpp
 3     > Author:sunshunzhong
 4     > Mail:13115543132@163.com 
 5     > Created Time: 2016年05月23日 星期一 15时39分33秒
 6  ************************************************************************/
 7 
 8 #include<iostream>
 9 using namespace std;
10 int main()
11 {
12     int a=5,b=6;
13     int *p1,*p2,p;
14     p1=&a;  // p1 存放 a 的值
15     p2=&b;
16       // b 的值赋给 a
17     cout<<"p2 "<<*p2<<endl;
18     p=*p2; // p=6
19     b=*p1; // b=5 p2=&b; *p2=5
20     cout<<"b:"<<b<<endl;
21     a=p;
22     cout<<"a:"<<a<<endl;
23     cout<<"p1:"<<*p1<<endl;
24     cout<<"p2:"<<*p2<<endl;
25     cout<<" a , b "<<a<<" "<<b<<endl;
26     return 0;
27 
28 }

posted @ 2016-05-23 17:06  #ifndef  阅读(385)  评论(0编辑  收藏  举报