Given an array of characters, how would you reverse it? How
would you reverse it without using indexing in the array?
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 |
In a switch statement, explain what will happen if a break statement is omitted?
explain what is a newline escape sequence?
what will happen if you free a pointer twice after allocating memory dynamically ?
How does pointer work in c?
how we can make 3d venturing graphics on outer interface
Did c have any year 2000 problems?
What is structure packing in c?
Explain how do you convert strings to numbers in c?
What is the hardest programming language?
How to find the given no is odd or even without checking of any condition and loops. (Hint: Using array)
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
write a program in c to read array check element is present or not?