write a program to swap Two numbers without using temp variable.

Answer Posted / yash paranjape

a=a^b;
b=a^b;
a=a^b;


i.e
a^=b;
b^=a;
a^=b;

more simplifie i.e in just one line
a^=b^=a^=b;

This also works fine

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is c# a good language?

600


Are c and c++ the same?

623


7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.

2213


What are the features of the c language?

636


How to write a multi-statement macro?

616






Why c is a procedural language?

574


design and implement a data structure and performs the following operation with the help of file (included 1000 student marks in 5 sub. and %also) 1.how many students are fail in all 5 subjects (if >35) 2. delete all student data those are fail in all 5 subjects. 3. update the grace marks (5 no. if exam paper is 100 marks) 4. arrange the student data in ascending order basis of marks. 5.insert double of deleted students with marks in the list.

1486


What are directives in c?

537


What are the different types of control structures?

576


Explain how can I pad a string to a known length?

639


Why C language is a procedural language?

612


What is a sequential access file?

644


What is operator precedence?

637


Describe the header file and its usage in c programming?

611


Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me

1452