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


Please Help Members By Posting Answers For Below Questions

How can you find the exact size of a data type in c?

602


what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)

1929


How #define works?

620


Is linux written in c?

602


What are the different types of endless loops?

625






Is c# a good language?

613


What are the advantages of the functions?

607


Describe newline escape sequence with a sample program?

659


What does it mean when the linker says that _end is undefined?

637


What does the && operator do in a program code?

698


When should a far pointer be used?

605


difference between Low, Middle, High Level languages in c ?

1635


Can a pointer point to null?

590


Explain bitwise shift operators?

633


Write a code on reverse string and its complexity.

609