how to swap two integers 1 and 32767 without using third
variable
Answer Posted / mansi_engg
use unsigned before variable a and b in
a=1;
b=32767;
a=a+b;
b=a-b;
a=a-b;
bcoj 32767+1 =32768 which goes out of range of integer and
will be stored as -32768 which wil make the swapping
wrong.by using unsigned, addition will come in range 0-65536
and thus the process works.
| Is This Answer Correct ? | 8 Yes | 2 No |
Post New Answer View All Answers
Why is c called c?
What does a function declared as pascal do differently?
What is a pointer in c?
How can a process change an environment variable in its caller?
Is there a way to switch on strings?
Write a simple code fragment that will check if a number is positive or negative.
Explain function?
What is non linear data structure in c?
List the different types of c tokens?
Ow can I insert or delete a line (or record) in the middle of a file?
Explain how do you declare an array that will hold more than 64kb of data?
What is difference between structure and union?
Is it possible to initialize a variable at the time it was declared?
What is the difference between typedef and #define?
What is #include conio h?