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

Why is sprintf unsafe?

0 Answers  


Are negative numbers true in c?

0 Answers  


write a program to gat the digt sum of a number (et. 15= >1+5=6)

2 Answers  


What are nested functions in c?

0 Answers  


what is the difference between malloc() and calloc() function?

1 Answers  






Linked list is a Linear or non linear explain if linear how it working as a non linear data structures

0 Answers  


Differentiate between new and malloc(), delete and free() ?

0 Answers   iNautix,


What is difference between structure and union in c?

0 Answers  


1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the character ch appears in the string. Example, the call countchtr(“She lives in NEWYORK”, ‘e’) would return 3.

4 Answers  


what is data structure.in linear and non linear data structures which one is better?Explain

3 Answers   Wipro,


find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }

0 Answers   Microsoft,


What is sizeof array in c?

0 Answers  


Categories