Reference Link : http://offclassroom.com/off-classroom/cc/282-swap-variables-in-c-without-using-temporary-variable.html
Hello friends! Being a final year computer engineering student, I have gone through so many C programming logics as a preparation of Interview (unfortunately still haven't got a chance to face it :-)
Recently one of my friends cleared the first two rounds of aptitude & programming and then got a chance to face the interview. He was asked so many logical questions on C & C++ . One of those question was, “How many different methods do you know to swap two variables without using a temporary variable?”
From this question, we can't give a particular answer as there might be so many logical solutions that can be used to swap two variables. I certainly know three:
Method 1: Swap two variables using + & - operators
Hello friends! Being a final year computer engineering student, I have gone through so many C programming logics as a preparation of Interview (unfortunately still haven't got a chance to face it :-)
Recently one of my friends cleared the first two rounds of aptitude & programming and then got a chance to face the interview. He was asked so many logical questions on C & C++ . One of those question was, “How many different methods do you know to swap two variables without using a temporary variable?”
From this question, we can't give a particular answer as there might be so many logical solutions that can be used to swap two variables. I certainly know three:
Method 1: Swap two variables using + & - operators
薛丁格的貓是奧地利物理學家埃爾溫·薛定諤用來解釋在宏觀情況下量力子學還不完整的假想性實驗