No one is gonna write code for him...he need to show some efforts.....i just gave a direction...he can work upon it and post his problem where he is stuck....
hey guys u r guessing something more
i just say that if u have written code thn give me
i was asking only for direction , tell me only logic ok i can do it
and keep in mind that sometimes one need something very instantly and this question was asked to my colleagues in interview and that time instantly he had no logic for it so i post u for help not for (underestimating things that i am giving u a order to write code on behalf me )
johnray31: I believe you are looking for the XOR swap.
So I guess you are being taught by a teacher that is still stuck in decades-old issues. This "save memory" thing was a problem before the 1970's and has been solved by hardware for decades.
Unfortunately these old hacks are still spread about as gleeming gems for programmers. Except that today, yesterday's optimization acutally is less optimal. And I doubt that your teacher will mention that this only works for integer types (that you cannot do this floating point values or pointers), and as the code in the link suggests you cannot use it on pointers to the same data. And let's hope you don't see the "supercompressed" version demonstrating undefined behavior proudly displayed in class as a wonderful solution.
So all-in-all, you're trying to learn something that you should try to forget after you've learned it.