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


Please Help Members By Posting Answers For Below Questions

Is c pass by value or reference?

587


Where register variables are stored in c?

536


what is the structure pointer?

1636


What’s a signal? Explain what do I use signals for?

597


Why isnt there a numbered, multi-level break statement to break out

581






What is static identifier?

693


What is static function in c?

621


Why is c faster?

583


Why c language is called c?

559


What is the difference between %d and %i?

584


What are the benefits of c language?

637


What is difference between union and structure in c?

567


Explain the difference between #include "..." And #include <...> In c?

614


What is the use of the function in c?

592


can anyone suggest some site name..where i can get some good data structure puzzles???

1637