Kodewick
Start learning →
Basic←→0 / 50

Print string in reverse

#048Basicreverse_print(s + 1)6 min

No loops: use recursion to finish reverse_print(s), which prints a string backwards, so "hello" shows as olleh. *s is the first character, and s + 1 is the rest of the string after it. Stopping at '\0' is already in the starter.

Should show
olleh
!99C
main.c
#include <stdio.h>

void reverse_print(const char *s) {
    if (*s == '\0') {
        return;
    }
    // your code here: first print the rest backwards
    // your code here: then print the first character
}

int main(void) {
    reverse_print("hello");
    printf("\n");
    reverse_print("C99!");
    printf("\n");
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.