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 |
How do you initialize pointer variables?
/*what is the output for the code*/ void main() { int r; r=printf("naveen"); r=printf(); printf("%d",r); getch(); }
Explain about C function prototype?
O,T,T,F,F,S,S,E,N,?,?,?,T,F,F,S,S,E,N
How will you allocate memory to double a pointer?
write a function for strtok()??
Write a program in C to reverse a number by recursive function?
9.how do you write a function that takes a variable number of arguments? What is the prototype of printf () function? 10.How do you access command-line arguments? 11.what does ‘#include<stdio.h>’ mean? 12.what is the difference between #include<> and #include”…”? 13.what are # pragma staments? 14.what is the most appropriate way to write a multi-statement macro?
int i=0,j; j=++i + ++i ++i; printf(" %d",j);
Why c is called top down?
write a code for large nos multilication (upto 200 digits)
Not all reserved words are written in lowercase. TRUE or FALSE?