Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Write a program with dynamically allocation of variable.

1068


What is a stream water?

1127


What is getch () for?

1149


#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }

1067


difference between native and cross compilers

2080


What is the meaning of 2d in c?

1064


What is the concatenation operator?

1090


hi any body pls give me company name interview conduct "c" language only

2231


Is file a keyword in c?

887


What are the header files used in c language?

995


Is return a keyword in c?

1030


a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion

2715


if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.

5142


Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

1034


what will be the output for the following main() { printf("hi" "hello"); }

10799