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...

Given an array of characters, how would you reverse it? How
would you reverse it without using indexing in the array?

Answer Posted / abdur rab

#include <stdio.h>

void reverse ( char* cp_str )
{
char* cp_rev_ptr = NULL;
cp_rev_ptr = cp_str;
while ( ( cp_rev_ptr ) && ( *cp_rev_ptr != '\0' ) )
cp_rev_ptr++;
cp_rev_ptr--;

while ( cp_str < cp_rev_ptr ) {
*cp_str ^= *cp_rev_ptr ^= *cp_str ^=
*cp_rev_ptr;
cp_str++;
cp_rev_ptr--;
}
}

int main ( int argc, char* argv [] )
{
char array [] = {"dlroW olleH"};

printf ("\nBefore :%s", array );
reverse ( array );
printf ("\nAfter :%s", array );

return ( 0 );
}

Output
======
Before :dlroW olleH
After :Hello World

Is This Answer Correct ?    16 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Where local variables are stored in c?

1012


what are the advantages of a macro over a function?

1146


Do array subscripts always start with zero?

1307


What is static memory allocation? Explain

1104


Is c is a high level language?

1194


How do you define a string?

1106


what is recursion in C

1071


Write a c program to build a heap method using Pointer to function and pointer to structure ?

4695


Explain what is the difference between null and nul?

1161


Who invented bcpl language?

1198


What is maximum size of array in c?

1047


what is uses of .net

1742


What are the different types of control structures in programming?

1136


.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }

1304


Explain how do you determine whether to use a stream function or a low-level function?

1092