Swapping of Two Numbers in C Without Temporary Variable

Swapping of Two Numbers in C Without Temporary Variable. Using this program we can interchange or swap the numbers in c without using a temporary variable or third variable.

Swapping Program in C

Swapping is the process of moving pages, memory segments, and values to a different location, as well as manipulating data files larger than the main memory. 

In memory, to replace pages or segments of data. Swapping is a technique that allows a computer to run programs and manipulate data files that are larger than the main memory.

Temporary Variable in C

A temporary variable is a variable in computer programming that has a short lifetime and is used to hold data that will be discarded soon or before it can be stored in a more permanent memory location. 

It is usually declared as a local variable, or a variable with local scope, because it is short-lived.

Swapping of Two Numbers in C Without Temporary Variable

#include<stdio.h> 
int main() 
{ 
int a=10, b=20; 
printf("Before Swap a=%d b=%d",a,b); 
a=a+b; 
b=a-b; 
a=a-b; 
printf("\nAfter Swap a=%d b=%d",a,b); 
return 0; 
} 

Output:

Before Swap a=10 b=20
After Swap a=20 b=10