没有中间变量的值交换
// Example program
#include <iostream>
#include <string>
void swap(int & a, int & b) {
a ^= b ^= a ^= b;
}
int main()
{
int a = 10;
int b = 100;
swap(a, b);
std::cout<<a<<'\t'<<b;
return 0;
}
// Example program
#include <iostream>
#include <string>
void swap(int & a, int & b) {
a ^= b ^= a ^= b;
}
int main()
{
int a = 10;
int b = 100;
swap(a, b);
std::cout<<a<<'\t'<<b;
return 0;
}