2个回答
展开全部
#include<stdio.h> void main() { void swap(int *x,int *y); int a,b,*p1,*p2; printf("请输入a和b的值:"); scanf("%d%d",&a,&b); p1=&a;p2=&b; swap(p1,p2); printf("交换后的值:"); printf("a=%d,b=%d\n",a,b); } void swap(int *x,int *y) { int temp; temp=*x; *x=*y; *y=temp; }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream> using namespace std; void swap(int *x, int *y); int main() { int x = 5, y = 10; cout << "Main. Before swap, x: " << x << " y: " << y << endl; swap(&x,&y); cout << "Main. After swap, x: " << x << " y: " << y << endl; return 0; } void swap (int *px, int *py) { int temp; cout << "Swap. Before swap, *px: " << *px << " *py: " << *py << endl; temp = *px; *px = *py; *py = temp; cout << "Swap. After swap, *px: " << *px << " *py: " << *py << endl; }
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询