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

In a switch statement, explain what will happen if a break statement is omitted?

0 Answers  


explain what is a newline escape sequence?

0 Answers  


what will happen if you free a pointer twice after allocating memory dynamically ?

3 Answers   Novell,


How does pointer work in c?

0 Answers  


how we can make 3d venturing graphics on outer interface

1 Answers   Microsoft,






Did c have any year 2000 problems?

0 Answers  


What is structure packing in c?

0 Answers  


Explain how do you convert strings to numbers in c?

0 Answers  


What is the hardest programming language?

0 Answers  


How to find the given no is odd or even without checking of any condition and loops. (Hint: Using array)

4 Answers  


in a town the percentage of men is 52 the percentage of total literacy is 48 if total percentage of literate men is 35 of the total population write a program to find the total no of the literate men and women if the population of the town is 80000

3 Answers  


write a program in c to read array check element is present or not?

1 Answers  


Categories