swap函数什么意思?

如题所述

swap函数一般是一个程序员自定义函数,是实现两个变量数值的交换。

1、比如:

int a = 2;

int b =3;

swap(a,b); //一般用到变量数值交换,交换后a=3 b = 2;

2、通过使用临时变量实现交换。

void swap1(int x,int y)

{

int temp;

temp=x;

x=y;

y=temp;

}

扩展资料

C语言swap函数的使用

#include<stdio.h>

void swap(int *pa,int *pb)

{

int temp;

temp=*pa,*pa=*pb,*pb=temp;

}

void main()

{

int a=10,b=20;

swap(&a,&b);//传递的是实参变量a,b的地址

printf("a=%d,b=%d\n",a,b);

}

温馨提示:答案为网友推荐,仅供参考