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

Write a program to use switch statement.

652


What are the different types of control structures in programming?

650


How can I call a function with an argument list built up at run time?

621


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

649


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

629






How macro execution is faster than function ?

656


What is %d called in c?

748


Differentiate abs() function from fabs() function.

588


What Is The Difference Between Null And Void Pointer?

630


Is it better to use a macro or a function?

644


Difference between malloc() and calloc() function?

648


How to explain the final year project as a fresher please answer with sample project

459


How can I sort a linked list?

628


How to implement a packet in C

2385


Why is c called c not d or e?

600