//倒置字符串 #include <iostream> using namespace std; //倒置原字符串 void reverse1(char * s) { if (s) { char temp; char * end=s; while (*end)//记住这里end只表示一个字符 { end++; } --end; while (s<end) { temp =*s; *s++=*end; *end-- =temp; } } } //返回个倒置字符串,不改变原字符串 char* reverse2(char * s,int m) { if(s) { char *temp =new char[m+1];//没有delete以后再看吧 //char temp[m+1]="0"; for (auto i =0;i<m;i++) { temp[i] = s[m-i-1]; } temp[m] ='\0'; return temp; } return s; } //倒着显示字符串 //递归 void show(char *s) { char temp; if(*s) { temp =*s++; show(s); cout<<temp; } } //不递归 用栈做 原理一样 void main() { char s[11] ="1234567890"; show(s); cout<<endl<<s<<endl; char *s1 =reverse2(s,strlen(s)); for (auto i =0;i<10;i++) { cout<<*s1++; } cout<<endl; reverse1(s); cout<<s<<endl; system("pause"); }