//
// main.c
//
// Created by Northcity on 15-6-23.
// Copyright (c) 2015年 tcg. All rights reserved.
//
#include <stdio.h>
//传统方法互换
void switch1(int *a,int *b){
int temp;
temp=*a;
*a=*b;
*b=temp;
}
//switch2 switch3方法原理基本一样
void switch2(int *a,int *b){
*a=*a+*b;
*b=*a-*b;
*a=*a-*b;
}
void switch3(int *a,int *b){
*a=*a^*b;
*b=*a^*b;
*a=*a^*b;
}
int main(int argc, const char * argv[])
{
int x,y;
scanf("%d %d",&x,&y);
// switch1(&x, &y);
// switch2(&x, &y);
switch3(&x, &y);
printf("%d %d\n",x,y);
return 0;
}
三种方法实现值互换
最新推荐文章于 2019-11-23 17:55:30 发布