string - C syntax, please explain this code snip? -



string - C syntax, please explain this code snip? -

can explain code below? how reversing order of chars in string?

void reverse_string(char *str) { /* skip null */ if (str == 0) { return; } /* skip empty string */ if (*str == 0) { return; } /* range */ char *start = str; char *end = start + strlen(str) - 1; /* -1 \0 */ char temp; /* reverse */ while (end > start) { /* swap */ temp = *start; *start = *end; *end = temp; /* move */ ++start; --end; }

it swaps first character , lastly character. swaps sec character next last. , on until it's done.

c string

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -