Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.
How to swap without third variable?
A variable is a named location in memory that is used to store data which can be modified in a program. Let us see how to swap two variables without using third variable. This can be done in number of namely
Let us see one of the method namely by using arithmetic operators.
Consider 2 variables say x=50 and y=70 and let us see how to swap the value of two variables that is make x=70 and y=50 without using third variable. This can be done by using following arithmetic operations namely
Which gives
Thus value of x and y gets swapped without using third variable and the whole program is given below:
This program gives output as
x=70 y=50
Profile Answers by GeekAdmin Questions by GeekAdmin
Questions by GeekAdmin answers by GeekAdmin
Related Answered Questions
Related Open Questions