can u write a program in C, which does not use = (eqaul)or
any arithmatic assignment(like -=,+=,*= etc) operator to
swap to number?
Answers were Sorted based on User's Feedback
Answer / musa
swapping x and y using z as intermediary
memcpy(&z, &x, sizeof(x));
memcpy(&x, &y, sizeof(x));
memcpy(&y, &z, sizeof(x));
Is This Answer Correct ? | 2 Yes | 1 No |
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 |
What are the differences between Structures and Arrays?
Write a programm such that if user enter 11.25 it roundup to 11 but if user enter 11.51 upto 11.99 it will round up to 12 i.e.;convert the floting point value into integer format as explain above..
Why c is procedure oriented?
what will be the output of this program........ main() { int a=2,b=4,c=6; printf("%d"); } why it gives the value of third variable.
What is the difference between printf and scanf )?
Write a C Programm.. we press 'a' , it shows the albhabetical number is 1, if we press 'g' it shows the answer 7.. any can help me
When was c language developed?
implement NAND gate logic in C code without using any bitwise operatior.
FIND THE OUTPUT IF THE INPUT IS 5 5.75 void main() { int i=1; float f=2.25; scanf("%d%f",&i,&f); printf("%d %f",,i,f); } ANSWER IS 5 AND 2.25 WHY?
What is the -> in c?
What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?
Does c have enums?