how to swap two integers 1 and 32767 without using third
variable

Answer Posted / sharath kumar

As int max valur is 32767. If we increment it it becomes -32768, so its a wrong way to do

a=1; b=32767;
a=-a; b=-b;
a=a+b; //-32768 with in range
b=a-b; //-1
a=a-b; //-32767
printf("%d%d",-a,-b);

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why should I use standard library functions instead of writing my own?

665


Write a Program to accept different goods with the number, price and date of purchase and display them

5426


Write a program to show the change in position of a cursor using c

573


What is the use of typedef in c?

574


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

630






What is the difference between declaring a variable by constant keyword and #define ing that variable?

2681


How do you list files in a directory?

553


What is wrong with this program statement?

601


What is a struct c#?

595


How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?

605


Compare and contrast compilers from interpreters.

673


What is the general form of a C program?

593


In a byte, what is the maximum decimal number that you can accommodate?

618


In C, What is the #line used for?

1037


What is the difference between struct and union in C?

559