#include <stdio.h>
// 交换变量
int main(void){
int a = 9;
int b = 2;
printf("a = %d , b = %d\n",a,b);
swap(&a,&b);
printf("after swap\na = %d , b = %d\n",a,b);
return 0;
}
void swap(int* a,int * b){
int t = *a;
*a = *b;
*b = t;
}
console log:
a = 9 , b = 2
after swap
a = 2 , b = 9Process returned 0 (0x0) execution time : 2.415 s
Press any key to continue.