<span style="font-family: Arial, Helvetica, sans-serif;">//reverse a string *str</span> <span style="font-family: Arial, Helvetica, sans-serif;"></span><pre name="code" class="cpp">//null字符不用反转,所以end指向字符串倒数第二个字符即可 //注意i++ 和++i的区别 //如果用递归处理这个问题呢? void reverse (char* str) { char* end = str; char temp; if(str) { while(*end) { ++end; } --end; //the last char is null, so we decrease one step of end while(str < end) { temp = *str; *str++ = *end; *end-- = temp; //swap value, then increase *str, decrease *end } } }