C Programming Code Examples C > Pointers Code Examples Swapping two numbers using Pointers Swapping two numbers using Pointers This is one of the most popular example that shows how to swap numbers using call by reference. #include <stdio.h> void swapnum(int *number1, int *number2) { int tempnum; tempnum = *number1; *number1 = *number2; *number2 = tempnum; } int main( ) { int v1 = 23, v2 = 88 ; printf("Before swapping:"); printf("\nValue of v1 is: %d", v1); printf("\nValue of v2 is: %d", v2); /*calling swap function*/ swapnum( &v1, &v2 ); printf("\nAfter swapping:"); printf("\nValue of v1 is: %d", v1); printf("\nValue of v2 is: %d", v2); }