版权声明:一辈子做程序员有何不可? https://blog.csdn.net/yoyo18520/article/details/8351698
开始写写博客,做做笔记,学习学习。
//利用指针的方法将"ADCD1234efgh"前后对调
#include <iostream>
#include <stdlib.h>
using namespace std;
char * swap(char * s)
{
char * p1 = s;
char * p2 = s + strlen(s) - 1;
char temp = '\0';
while(p1 < p2)
{
temp = *p1;
*p1 = *p2;
*p2 = temp;
p1++;
p2--;
}
return s;
}
int main()
{
char s[100];
cout << "请输入一串字符:";
cin >> s;
cout << "显 示 结 果:" << swap(s) << endl;
system("pause");
return 0;
}
显示结果: