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

Explain what are binary trees?

1034


Are pointers really faster than arrays?

972


1) write a program to generate 1st n fibonacci prime numbers using Nested if 2) write a program to generate twin prime numbers from m to n using nested if 3) write a program to check whether a given integer is a strong number or not using nested if 4) Write a program to generate prime factors of a given integer using nested if 5)write a program to generate prime numbers from m to n using nested if 6)write a program to generate perfect numbers from m to n using nested if 7)write a program to generate the pallindromes from m to n using neste if 8)write a program to generate armstrong numbers from m to n using nested if 9)write a program to generate strong numbers from m to n using nested if

4557


How can my program discover the complete pathname to the executable from which it was invoked?

1039


How do you define CONSTANT in C?

1218


What is variable initialization and why is it important?

1181


What is getch?

1112


When should structures be passed by values or by references?

1004


Do you have any idea how to compare array with pointer in c?

1002


A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.

1685


What are the 5 types of organizational structures?

1032


Describe newline escape sequence with a sample program?

1078


What is the advantage of using #define to declare a constant?

1045


What is preprocessor with example?

1008


How can variables be characterized?

2141