Write a recursive function to print reverse of a given string.
skeeG rof skeeG
Explanation: Recursive function (reverse) takes string pointer (str) as input and calls itself with next location to passed pointer (str+1). Recursion continues this way, when pointer reaches ‘\0’, all functions accumulated in stack print char at passed location (str) and return one by one.
Time Complexity: O(n)
See Reverse a string for other methods to reverse string.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Print reverse string after removing vowels
- Print words of a string in reverse order
- Create a new string by alternately combining the characters of two halves of the string in reverse
- Print Strings In Reverse Dictionary Order Using Trie
- Convert a String to an Integer using Recursion
- Program for length of a string using recursion
- Length of longest palindromic sub-string : Recursion
- Move all occurence of letter 'x' from the string s to the end using Recursion
- Print shortest path to print a string on screen
- Product of nodes at k-th level in a tree represented as string using Recursion
- Reverse words in a given string
- Different methods to reverse a string in C/C++
- Reverse vowels in a given string
- Reverse the given string in the range [L, R]
- Reverse a string in Java