Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is null pointer in c?

998


How can you draw circles in C?

1156


When the macros gets expanded?

1428


What is cohesion in c?

983


Tell me when would you use a pointer to a function?

1067


In a switch statement, explain what will happen if a break statement is omitted?

1077


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

1037


What are loops c?

1057


c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above

1263


Write a c program to demonstrate character and string constants?

2193


Explain the advantages and disadvantages of macros.

1105


How can I get the current date or time of day in a c program?

1228


Why void is used in c?

1020


Can we replace the struct function in tree syntax with a union?

1312


Explain how can I remove the trailing spaces from a string?

1051