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 are the advantage and disadvantage of recursion

5 Answers  


write a program to concatenation the string using switch case?

0 Answers  


1)what are limitations for recursive function? 2)write a program to read a text file and count the number of characters in the text file

1 Answers  


What is the advantage of a random access file?

0 Answers  


the process of defining something in terms of itself is called (or) in C it is possible for the functions to call themselves. A function called a) nested function b) void function c) recursive function d) indifinite function

0 Answers  






Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

0 Answers  


Explain what is the difference between text files and binary files?

0 Answers  


What are the different types of C instructions?

0 Answers   InterGraph,


Find the O/p of the following 1) #include int main() { char c='1'; int j=atoi(c); }

4 Answers   Subex,


How to implement variable argument functions ?

1 Answers   HP,


Find string palindrome 10marks

5 Answers   Honeywell, Infosys, Riktam, Roland,


In a byte, what is the maximum decimal number that you can accommodate?

0 Answers  


Categories