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

How pointers are declared?

556


What is the difference between the expression “++a” and “a++”?

644


What is the use of getch ()?

627


Explain the meaning of keyword 'extern' in a function declaration.

712


Write the Program to reverse a string using pointers.

612






Should I learn c before c++?

593


Where in memory are my variables stored?

628


Why is c used in embedded systems?

604


What is calloc in c?

654


What is typedef example?

610


What does s c mean in text?

604


Is it possible to have a function as a parameter in another function?

594


The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration

622


how to write a c program to print list of fruits in alpabetical order?

1784


I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.

1733