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
Write a program to use switch statement.
What are the different types of control structures in programming?
How can I call a function with an argument list built up at run time?
Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?
a program that performs some preliminary processing in C, it acts upon certain directives that will affect how the compiler does its work a) compiler b) loader c) directive d) preprocessor
How macro execution is faster than function ?
What is %d called in c?
Differentiate abs() function from fabs() function.
What Is The Difference Between Null And Void Pointer?
Is it better to use a macro or a function?
Difference between malloc() and calloc() function?
How to explain the final year project as a fresher please answer with sample project
How can I sort a linked list?
How to implement a packet in C
Why is c called c not d or e?