字符串逆转
一个字符串逆转,记录一下,主要是用到移位,没有用临时变量,面试中很可能考到。
int main()
{
char p[] = "123456789";
int len = strlen(p) ;
int j = len-1;
for(int i=0;i<j;i++,j--)
p[i]^=p[j]^=p[i]^=p[j];
cout<<p;
system("pause");
return 0;
}
{
char p[] = "123456789";
int len = strlen(p) ;
int j = len-1;
for(int i=0;i<j;i++,j--)
p[i]^=p[j]^=p[i]^=p[j];
cout<<p;
system("pause");
return 0;
}