
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
