How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / asif
#include <stdio.h>
#include <string.h>
void reverse(char *str)
{
if (*str == '\0')
return;
reverse(str+1);
printf("%c", *str);
}
int main()
{
char str[50];
char *ptr;
printf("Enter the string: ");
//scanf("%s", str);
fgets(str,50,stdin);
ptr = strchr(str,'\n');
*ptr = '\0';
printf("Reversed string: ");
reverse(str);
printf("\n");
return 1;
}
Is This Answer Correct ? | 2 Yes | 3 No |
Post New Answer View All Answers
what are non standard function in c
Explain zero based addressing.
What is new line escape sequence?
What does double pointer mean in c?
What are the __date__ and __time__ preprocessor commands?
Explain output of printf("Hello World"-'A'+'B'); ?
How do you declare a variable that will hold string values?
Explain what is the heap?
What is the difference between %d and %i?
Why is c called "mother" language?
Why can’t we compare structures?
How can I split up a string into whitespace-separated fields?
Is stack a keyword in c?
Explain union. What are its advantages?
Write a code to generate divisors of an integer?