#include
#include
int main(void)
{
char str[80];
int i,j;
puts('Enter a string:');
gets(str);
for(i=0,j=strlen(str)-1;i
str[i]^=str[j]^=str[i]^=str[j];
}
puts(str);
putchar('\n');
return 0;
}
str[i]^=str[j]^=str[i]^=str[j];
上面这步,非常精炼 虽然只有一行式子,却完成了前后的交换
解析:设
a = 1 0
b = 1 1
a1= a^b = 0 1
b1=a1^b = 1 0 = a
a2=b1^a1= 1 1 = b