Theory
Swapping is used in various programs like sorting the array. It is mainly used in the area when we want to store old values without using much space. So in Conclusion if we have taken a=10 and b=20 then after swapping it should become b=10 and a=20. Swapping can be done using various methods like taking a third variable and then swapping it or without using third variable swapping it through + and - operators or * and / operators. I will be discussing first method using third variable and then without using third variable.
Why use swapping in C language?
It is used to improve main memory utilization. In secondary memory, the place where the swapped-out process is stored is called swap space. The purpose of the swapping in operating system is to access the data present in the hard disk and bring it to RAM so that the application programs can use it.
Advantage of swapping in C
1) It helps the CPU to manage multiple processes within a single main memory.
2) It helps to create and use virtual memory.
3) Swapping allows the CPU to perform multiple tasks simultaneously.
4)It improves the main memory utilization.
Types of C Swapping
There are two types of swapping in C language that is given below:
1. Swapping Of Two Numbers With Using a Third Variable.
2. Swapping of two numbers without using third/temp variable.
The syntax for swapping in c language is given below:
swap(x, y);
{
printf ( "\nAfter Swapping: x = %d, y = %d" , x, y); return 0;
}
Flowchart of swapping in c:

