表示还是想了一段时间的,C长时间没看比较晕了:
#include <iostream> using namespace std; char* reversal(char *test,int size) { char *test1 = new char[size]; int tmp = size-2 ; for (int i = 0; i <= tmp; ++i) { test1[i] = test[tmp-i]; } test1[size-1]='\0'; return test1; } int main() { char a[]="abcdefg"; int size = sizeof(a)/sizeof(*a); cout << reversal(a,size) << endl; }