write a C code
to reverse a string using a recursive function, without
swapping or using an extra memory.
Answer Posted / mohan
#include <stdio.h>
#include <string.h>
void reverse(char **s, int start, int last)
{
char tmp;
if (start >= last)
return;
char *s2 = *s;
tmp = s2[start];
s2[start] = s2[last];
s2[last] = tmp;
reverse(s, start + 1, last - 1);
}
int main()
{
char *s = strdup("Hello World");
printf("%s\n", s);
reverse(&s, 0, strlen(s) - 1);
printf("%s\n", s);
}
Is This Answer Correct ? | 5 Yes | 1 No |
Post New Answer View All Answers
Write a C program in Fibonacci series.
What are the 32 keywords in c?
How can I do graphics in c?
What is the difference between test design and test case design?
Why is sizeof () an operator and not a function?
What is s in c?
Why header file is used in c?
What are the functions to open and close the file in c language?
What is the difference between near, far and huge pointers?
5 Write an Algorithm to find the maximum and minimum items in a set of ānā element.
Which header file is used for clrscr?
Why use int main instead of void main?
What is an identifier?
What is 2 d array in c?
What is Dynamic memory allocation in C? Name the dynamic allocation functions.