From f771fbd1a986fa8d6b80cf152c1b77f7c2424945 Mon Sep 17 00:00:00 2001 From: haoxuan Date: Sat, 14 Mar 2026 05:07:02 -0400 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=E3=80=8C/=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用指针交换两个数 --- 23a.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 23a.cpp diff --git a/23a.cpp b/23a.cpp new file mode 100644 index 0000000..3b2a649 --- /dev/null +++ b/23a.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; +int main(){ + int * ptr_a, * ptr_b,temp; + ptr_a = new int; + ptr_b = new int; + cout<<"请输入*ptr_a的值:"; + cin>>*ptr_a; + cout<<"请输入*ptr_b的值:"; + cin>>*ptr_b; + temp=*ptr_a; + *ptr_a=*ptr_b; + *ptr_b=temp; + cout<<*ptr_a<<" "<<*ptr_b<