两种字符串逆序的方法

#include<iostream>
#include<map>
#include<algorithm>
#include<numeric>
using namespace std;

void helper(char* str) ///用指针实现,注意strlen的用法,并且没有动最后的
{
  int len = strlen(str);
  int pleft = 0;
  int pright = len - 1;
  while(pleft < pright)
  {
   swap(str[pleft],str[pright]);
   pleft++;
   pright--;
  }
  printf("%s",str);
}

void helper1(char* str) ///用异或运算实现的,注意方法
{
  char* r = str;
  char* p = str;
  while(*(p+1) != '') ++p;
  while(p>r)
  {
   *p = *p^*r;
   *r = *p^*r;
   *p = *p--^*r++;
  }
  printf("%s",str);
}

int main()
{
//    char* s = "abcdefg";
    char s[] = "abcdefg";
    helper(s);
}
berkeleysong
原文地址:https://www.cnblogs.com/berkeleysong/p/3741054.html