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
What is function prototype in c with example?
Is null a keyword in c?
How to write a code for implementing my own printf() and
scanf().... Please hep me in this... I need a guidance...
Can you give an coding for c... Please also explain about
the header files used other than #include
What is use of bit field?
How can a process change an environment variable in its caller?
how logic is used
Where static variables are stored in c?
What is the general form of #line preprocessor?
What 'lex' does?
What is the modulus operator?
Explain how can I write functions that take a variable number of arguments?
What is nested structure with example?
What are the types of i/o functions?
How can I swap two values without using a temporary?
What is a struct c#?