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
Can you please explain the difference between malloc() and calloc() function?
Is c is a procedural language?
formula to convert 2500mmh2o into m3/hr
How many loops are there in c?
How can I make sure that my program is the only one accessing a file?
Why static variable is used in c?
please give me some tips for the placement in the TCS.
What is the Purpose of 'extern' keyword in a function declaration?
How is a null pointer different from a dangling pointer?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
What do mean by network ?
write a program to display all prime numbers
Is c programming hard?
Explain about block scope in c?
What is spaghetti programming?