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
Explain what is the difference between null and nul?
Which header file is essential for using strcmp function?
What are the basic data types associated with c?
Which header file is used for clrscr?
How pointer is different from array?
Explain what is operator promotion?
What is this pointer in c plus plus?
Write the test cases for checking a variable having value in range -10.0 to +10.0?
Why is c still so popular?
Differentiate between a for loop and a while loop? What are it uses?
Between macros and functions,which is better to use and why?
What are the advantages of the functions?
Why #include is used in c language?
What is 2 d array in c?
Explain the concept and use of type void.