int main(int argc, const char * argv[]) {
@autoreleasepool {
int a = 10, b = 20;
NSLog(@”before,a = %d”,a);
NSLog(@”before,b = %d”,b);
//第一种方法,数学运算
/*
a = a + b;
b = a – b;
a = a – b;
*/
//第二种方法,位异或运算
/*
a = a^b;
b = a^b;
a = a^b;
*/
//第三种方法,使用指针
int *pa = &a;
int *pb = &b;
*pa = b;
*pb = a;
NSLog(@”after,a = %d”,a);
NSLog(@”after,b = %d”,b);
}
return 0;
}