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
How can you find the exact size of a data type in c?
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
How #define works?
Is linux written in c?
What are the different types of endless loops?
Is c# a good language?
What are the advantages of the functions?
Describe newline escape sequence with a sample program?
What does it mean when the linker says that _end is undefined?
What does the && operator do in a program code?
When should a far pointer be used?
difference between Low, Middle, High Level languages in c ?
Can a pointer point to null?
Explain bitwise shift operators?
Write a code on reverse string and its complexity.