You can switch or interchange two variables without the use of an additional or temporary variable by using arithmetic operations as follows:
- Add both variables and store the result in one of the variables.
Example:
a = a + b
- Subtract the value of one variable (which now contains the sum of both variables) from the other variable and store the result in the same variable.
Example:
b = a - b
- Subtract the value of one variable (which now contains the original value of the other variable) from the same variable and store the result in the other variable.
Example:
a = a - b
After these operations, the values of variables a and b will be interchanged without using any additional variables.