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 I dynamically allocate arrays?
What is local and global variable in c?
the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b
Write a program to find the biggest number of three numbers in c?
What do you mean by a local block?
Is javascript written in c?
Which is better between malloc and calloc?
Tell me when would you use a pointer to a function?
What is difference between array and structure in c?
Write a program for Overriding.
Which is better pointer or array?
Explain the difference between null pointer and void pointer.
Mention four important string handling functions in c languages .
What are the 5 organizational structures?
If you know then define #pragma?