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
What is the g value paradox?
What are enums in c?
Explain the difference between exit() and _exit() function?
What functions are used for dynamic memory allocation in c language?
What oops means?
What is return in c programming?
write a programe to accept any two number and check the following condition using goto state ment.if a>b,print a & find whether it is even or odd and then print.and a
Tell me can the size of an array be declared at runtime?
please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code
What is struct node in c?
Can you tell me how to check whether a linked list is circular?
How to write a code for implementing my own printf() and
scanf().... Please hep me in this... I need a guidance...
Can you give an coding for c... Please also explain about
the header files used other than #include
In c programming language, how many parameters can be passed to a function ?
how do you execute a c program in unix.
How can you access memory located at a certain address?