← C-Strings

Reverse a String

medium

Reverse word in place, character by character – the exact same converging two-pointer/two-index technique used to reverse an int array earlier in this module, adapted to a string: find the length with strlen, swap the first and last characters, then the second and second-to-last, and so on until the two indices meet or cross.

The null terminator itself never needs to move – it’s already sitting in the right place, one past the last real character, before and after the reversal. Only the len characters before it get swapped.

Your solution

"Run" uses the sample stdin ("hello"). "Submit" checks your code against all 4 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution