C Program to Swap Two Numbers / Variables using Pointer

Swap Two Numbers / Variables using Pointer :

Output :

Explanation : Swapping Two Variables using Pointer

Firstly we need to accept two numbers using scanf statement like this –

Now You need to pass the address of both variables to the function. Parameter passing scheme is called as Pass by Pointer.
Now Take a look at function definition, We have passed address of two variables from main function to swap function. So we need variable container that can store the address of integer variables i.e Integer Pointers.
Thus address of first number will be collected in “num1” pointer variable and second number will be collected in “num2” pointer variable.