how to swap two numbers with out using temp variable

Answer Posted / a.g.dhivyalakshmi

//swaping of 2 numbers without using temp variable
//a=5 & b=6
a=a+b; //a=30
b=a-b; //b=5
a=a-b; //a=6

//Thus two numbers are swapped

// or
//a=5 & b=6
a=a*b; //a=30
b=a/b; //b=5
a=a/b; //a=6

//Thus two numbers are swapped

Is This Answer Correct ?    8 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what are Access specifiers in C++ class? What are the types?

711


Differentiate between realloc() and free().

674


Why isn't sizeof for a struct equal to the sum of sizeof of each member?

622


Explain unexpected() function?

682


What is the difference between public and private data members?

754






What are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random

760


Explain function overloading

666


What are pointers used for c++?

671


How do I use arrays in c++?

665


Why is c++ difficult?

686


What is a buffer c++?

669


Does c++ vector allocate memory?

629


What is &x in c++?

664


What is Destructor in C++?

765


What does the nocreate and noreplace flag ensure when they are used for opening a file?

761