can u write a program in C, which does not use = (eqaul)or
any arithmatic assignment(like -=,+=,*= etc) operator to
swap to number?
Answer Posted / anish
Simple... use XOR (^) operator...
example suppose,
x=101 (binary)
y=010 (binary)
now,
Execute : x=x^y; -->> from LSB 1^0=1 0^1=1 1^0=1
now x=111
Execute : y=x^y; -->> from LSB 1^0=1 1^1=0 1^0=1
now y=101 (101 used to be the value of x)
Execute : x=x^y; -->> from LSB 1^1=0 1^0=1 1^1=0
now x=010 (010 used to be the values of y)
code snippet
{
x=10;
y=30;
//swap x and y
x=x^y;
y=x^y;
x=x^y;
}
now x=30 and y=10
any doubts please ask me....
Is This Answer Correct ? | 3 Yes | 8 No |
Post New Answer View All Answers
In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.
Why is c known as a mother language?
how to print the character with maximum occurence and print that number of occurence too in a string given ?
What is a static variable in c?
Explain how do you sort filenames in a directory?
What is string concatenation in c?
Explain modulus operator.
How many main () function we can have in a project?
Can you explain the four storage classes in C?
What is the difference between procedural and declarative language?
What’s the special use of UNIONS?
Does c have class?
In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none
How do you print only part of a string?
Do pointers store the address of value or the actual value of a variable?