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 are 'near' and 'far' pointers?

616


Write a C program to count the number of email on text

1412


Explain what are run-time errors?

605


Tell us the use of fflush() function in c language?

635


Write a program of advanced Fibonacci series.

704






write a c program in such a way that if we enter the today date the output should be next day's date.

1677


What is the translation phases used in c language?

628


What is main function in c?

546


What does %c do in c?

580


Write programs for String Reversal & Palindrome check

594


.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }

1993


Should I learn data structures in c or python?

576


What is typedef struct in c?

581


What is d scanf?

586


What is the difference between text and binary modes?

639