Can anyone explain the code given below? How is the order of the characters being returned in the string?
void reverse_string (char * str) {/ * skip null * / if (str == 0) {return; } / * Leave the empty string * / if (* str == 0) {return; } / * Get the range * / char * start = str; Char * end = start + strlen (str) - 1; / * 1 for \ 0 * / char temp; / * Reverse * / while (and & gt; start) {/ * swap * / temp = * start; * Start = * end; * End = temp; / * Move * / ++ start; --End; }
It swaps the first letter and the last character, then it with the next character Swaps the other character and so long as it has not happened.
Comments
Post a Comment