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
In a header file whether functions are declared or defined?
What are the main characteristics of c language describe the structure of ac program?
Are comments included during the compilation stage and placed in the EXE file as well?
What are dangling pointers? How are dangling pointers different from memory leaks?
write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1
Can two or more operators such as and be combined in a single line of program code?
Explain what are multibyte characters?
Write a program that accept anumber in words
In a switch statement, what will happen if a break statement is omitted?
What is the most efficient way to store flag values?
Do array subscripts always start with zero?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
How macro execution is faster than function ?
What are the advantages of the functions?
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?