How to write a program for swapping two strings without
using 3rd variable and without using string functions.

Answer Posted / saptarshi

void main()
{
char *p="string1";
char *q="string2";

p^=q^=p^=q;
printf("%s,%s",p,q);
}

swapping the base pointers of the two strings may work...
if they are declared as character arrays, then it is not
possible as we cannot modify the value of array base
pointers...

Is This Answer Correct ?    10 Yes 26 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a function simple definition?

840


What is difference between class and structure?

824


What does %c do in c?

780


What are the types of data files?

920


Explain union.

898


What is function prototype in c language?

808


When should you not use a type cast?

881


Can we access array using pointer in c language?

842


how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

1727


Do pointers store the address of value or the actual value of a variable?

819


Why is sprintf unsafe?

800


main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }

1145


main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }

848


What are the applications of c language?

835


Explain what are preprocessor directives?

817