变量交换

看到一种两变量交换的新方法,不需要临时变量,只适用于数值变量。

#include<stdio.h>
int main()
{
    int a, b;
    scanf("%d%d",&a,&b);
    a = a + b;
    b = a - b;
    a = a - b;
    printf("%d %d
",a,b);
    return 0;
 } 

仅此提供新思路,没有太大实用价值。

只能预防有人问你:不使用临时变量,交换两个整形变量的值。

原文地址:https://www.cnblogs.com/Boxer1994/p/5859230.html