Swapping of two numbers means interchanging their values.
This can be easily done with the help of a third temp variable.
However, swapping two variables without using the third variable is little bit tricky. In this program,
we will perform swapping using a third temp variable.
C program to swap two numbers using a third variable - Source code
Program Output
Program Explanation
1. In the above program, first, the temp variable is assigned the value of first number a.
2. Then, the value of first number a is assigned to second number(b).
3. Finally, the temp variable (which holds the initial value of a) is assigned to variable b, which completes the swapping process.
4. Note that, here, temp variable is used to hold the value of first variable a and doesn't have any other use except that.
need an explanation for this answer? contact us directly to get an explanation for this answer