运用传址调用来交换两个数
#include<stdio.h>
int transform(int* a, int* b)
{
int x = 0;
x = *a;
*a = *b;
*b = x;
}
int main()
{
int a = 10;
int b = 20;
printf("交换前:%d %d\n", a, b);
transform(&a, &b);
printf("交换后:%d %d\n", a, b);
return 0;
}
运行结果:
请多多指教 有问题请在评论区评论!!
标签:传址,调用,int,交换,transform,C语言,printf,心得 From: https://blog.51cto.com/u_16285697/7852705