How do you swap two numbers without using a third variable in C by arithmatic operations?

Arithmatic swap without a 3rd variable

int iA = 5;
int iB = 6;
int iA = iA + iB; // iA is now 11
int iB = iA - iB; // iB is now 5
int iA = iA - iB; // iA is now 6

Note: Even though no overt variable has been created, the compiler has created temporary variables because a variable left of the equal sign has been used on the right.




Improve Answer Discuss the question "How do you swap two numbers without using a third variable in C by arithmatic operations?" Watch Question

First answer by ID1167588123. Last edit by ID1167588123. Question popularity: 9 [recommend question]

Research your answer:

Answers.com > Wiki Answers > Categories > Technology > Computers > Computer Programming > How do you swap two numbers without using a third variable in C by arithmatic operations?

Our contributors said this page should be displayed for the questions below. (Where do these come from)
If any of these are not a genuine rephrasing of the question, please help out and edit these alternates.
Swap two numbers?  How do you swap a two variable?  How do you swap two numbers in c?  Where to use arithmatic progression formulae?  How do you swap two numbers in single statements?  C Programme for swap two numbers using a third variable?  What are the arithmatic operations on pointers in c prgraming?  What is it when you substitute numbers in for the variables and follow the order of operations?