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
What is the difference between scanf and fscanf?
How to write a code for implementing my own printf() and
scanf().... Please hep me in this... I need a guidance...
Can you give an coding for c... Please also explain about
the header files used other than #include
Explain how do you print only part of a string?
What does s c mean on snapchat?
a c code by using memory allocation for add ,multiply of sprase matrixes
Is main a keyword in c?
What is conio h in c?
What is variable declaration and definition in c?
Is main an identifier in c?
What language is c written?
What are the advantage of c language?
What is a null pointer in c?
How do c compilers work?
What is the difference between far and near ?
write a progrmm in c language take user interface generate table using for loop?