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

How does free() know explain how much memory to release?

0 Answers  


What is d'n in c?

0 Answers  


what is pointer ? what is the use of pointer?

6 Answers   Infosys,


what is output of the following statetment?Printf(“%x”, -1<<4); ?

5 Answers  


What is the size of enum in bytes?

0 Answers  


i want to asked a question about c program the question is: create a c program that displays all prime numbers less than 500? using looping statement

5 Answers  


the maximum value that an integer constant can have is a) -32767 b) 32767 c) 1.701e+38 d) -1.7014e+38

1 Answers  


What is the difference between union and anonymous union?

0 Answers   Hexaware,


I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.

0 Answers   Oracle,


I have an array of 100 elements. Each element contains some text. i want to: append a star character to the end of every fifth element remove every second character from every tenth element, and… add a line feed (ascii 10) after the 30th character of every array element whose length is greater than 30 characters.

1 Answers  


EXPLAIN #INCLUDE<STDIO.H> EXPLAIN #INCLUDE<CONIO.H>

4 Answers  


Write a C program to find the smallest of three integers, without using any of the comparision operators.

7 Answers   TCS,


Categories