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 to print numbers from 1 to 100 without using loop in c?

1040


Do you have any idea about the use of "auto" keyword?

1059


What is a sequential access file?

1119


Is it better to use malloc() or calloc()?

1080


Is c is a procedural language?

1045


What are the 5 organizational structures?

985


Function calling procedures? and their differences? Why should one go for Call by Reference?

1058


What is c language in simple words?

1026


What is a keyword?

1131


What does volatile do?

947


Is there a built-in function in C that can be used for sorting data?

1197


What is the difference between far and near ?

1164


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

1060


Linked list is a Linear or non linear explain if linear how it working as a non linear data structures

2133


What are header files and what are its uses in C programming?

1156