Files
homework/指针/交换值 .cpp
2026-03-07 00:47:37 -05:00

16 lines
373 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 }