指针 (更换地址保存的地址)

 1 /*
 2 指针 (更换地址保存的地址)
 3 2017-1-11 16:59:24 
 4 
 5 */
 6 
 7 
 8 # include <iostream>
 9 using namespace std;
10 int main()
11 {
12     int i=10,j=20;
13     int *p=&i;//"p"是一个地址;"*p"是一个值 
14     cout<<i<<endl;
15     cout<<&i<<endl;
16     cout<<j<<endl;
17     cout<<&j<<endl;
18     cout<<p<<endl;
19     cout<<*p<<endl;
20     p=&j;   //地址和值都会被代替 
21     cout<<"更换地址后"<<endl;
22     cout<<i<<endl;
23     cout<<&i<<endl;
24     cout<<j<<endl;
25     cout<<&j<<endl;
26     cout<<p<<endl;
27     cout<<*p<<endl;
28     return 0;
29     
30 }
View Code

 

 

posted on 2017-01-11 17:03  冰樱梦  阅读(205)  评论(0编辑  收藏  举报

导航