forked from newde/homework
新增 指针/交换值 .cpp
This commit is contained in:
16
指针/交换值 .cpp
Normal file
16
指针/交换值 .cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
1 #include<iostream>
|
||||||
|
2 using namespace std;
|
||||||
|
3
|
||||||
|
4 int main(){
|
||||||
|
5 int a=10,b=5,temp,*ptr_a,*ptr_b;
|
||||||
|
6 cout<<"a的值是:"<<a<<" b的值是:"<<b<<endl;
|
||||||
|
7 ptr_a=&a;
|
||||||
|
8 ptr_b=&b;
|
||||||
|
9 temp=*ptr_a;
|
||||||
|
10 *ptr_a=*ptr_b;
|
||||||
|
11 *ptr_b=temp;
|
||||||
|
12
|
||||||
|
13 cout<<"交换后a的值是:"<<a<<" b的值是:"<<b<<endl;
|
||||||
|
14
|
||||||
|
15 return 0;
|
||||||
|
16 }
|
||||||
Reference in New Issue
Block a user