how to reverse string "Hello World" by using pointers only.
Without any temp var



how to reverse string "Hello World" by using pointers only. Without any temp var..

Answer / aravind

#include<stdio.h>
char reverse(char *, char *);
int main()
{
char a[]="hello"
char b[]="world";
gets(a,b);
puts(a); /*displays Hello world*/
reverse(a,b);

char reverse(char *ptr, char *ptr1)
{
int i,j;
for(i=0;i!='\0';i++)
{
printf("%s",*ptr);
ptr++;
}
for(j=0;j!='\0';j++)
{
printf("%s",*ptr1);
ptr1++;
}
gets(*ptr1,*ptr);
puts(*ptr1); /*displays world hello*/
}

Is This Answer Correct ?    0 Yes 10 No

Post New Answer

More C Interview Questions

string reverse using recursion

0 Answers   Mind Tree,


Explain how can you be sure that a program follows the ansi c standard?

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 the use of the function in c?

0 Answers  


What is the difference between char a[] = "string"; and char *p = "string"; ?

14 Answers   Adobe, Honeywell, TCS,






What are disadvantages of C language.

0 Answers   iNautix,


How do you define structure?

0 Answers  


what is the output? #define fun(a,b,t) (g ##t=(a),(a)=(b),(b)=g##t) float gfloat; main() { float a=1.12,b=3.14; fun (a,b,float); printf("na=%4.2f,b=%4.2f",a,b); } A)Error in Defining Macro B)a=1.12,b=3.14 C)a=3.14,b=1.12 D)None of the Above

3 Answers   Accenture, Infosys, Wipro,


Write a C program to perform some of the operation which can be performed using Single linked list

1 Answers   Qualcomm,


List a few unconditional control statement in c.

0 Answers  


Compare array data type to pointer data type

0 Answers  


while initialization of two dimensional arrays we can initialize like a[][2] but why not a[2][] is there any reason behind this?

4 Answers   Aptech,


Categories