Given an array of characters, how would you reverse it? How
would you reverse it without using indexing in the array?



Given an array of characters, how would you reverse it? How would you reverse it without using ind..

Answer / 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

More C Interview Questions

What is a class?

3 Answers  


what is the difference between exit() and _exit() functions?

2 Answers  


Write a program in c to print * * * * * *******

1 Answers  


Explain the red-black trees?

0 Answers  


what is self refrential structure

3 Answers   HCL,


Can u please send me the exam pattern and also Previous papers to javed123go@gmail.com

0 Answers  


Write a program to reverse a linked list in c.

0 Answers   DELL, HAL,


What is the mean of this statement:: if(int i=0 * i=9)

2 Answers   HCL,


Can we replace the struct function in tree syntax with a union?

0 Answers   Huawei,


What are runtime error?

0 Answers  


What is a structure in c language. how to initialise a structure in c?

0 Answers  


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

0 Answers  


Categories