How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / boomer
void Rstring( char *str,int len)
{
for(int i = 0; i < (len/2); i++)
{
str[i] ^= str[len-i-1];
str[len-i-1] ^= str[i];
str[i] ^= str[len-i-1];
}
}
int main( void )
{
char str[] = "my string";
printf("Actual string is [%s]\n", str);
Rstring(str,strlen(str));
printf("Reversed string is [%s]\n", str);
}
I dont call this swaping, coz it's not, recursive creates
new incarnations of the reverse func, EXTRA MEMORY BIG
TIME!!!
| Is This Answer Correct ? | 21 Yes | 40 No |
Post New Answer View All Answers
what is the basis for selection of arrays or pointers as data structure in a program
What is a const pointer in c?
if (i = 0)printf ("True"); elseprintf("False"); Under what conditions will the above print out the string "True" a) Never b) Always c) When the value of i is 0 d) all of the above
What are the different types of pointers used in c language?
What is a program?
praagnovation
What is the meaning of c in c language?
we called a function and passed something do it we have always passed the "values" of variables to the called function. such functions calles are called a) calls by reference b) calls by value c) calls by zero d) none of the above
Explain the difference between ++u and u++?
By using C language input a date into it and if it is right?
Describe dynamic data structure in c programming language?
When is a null pointer used?
What is define c?
Can you tell me how to check whether a linked list is circular?
Explain what is the difference between the expression '++a' and 'a++'?