C Programming Code Examples C > Beginners Lab Assignments Code Examples Swapping Two Numbers Using Variable in C Swapping Two Numbers Using Variable in C In many case, programmers are required to swap values of two variables. Here, we shall learn how to swap values of two integer variables, that may lead to swapping of values of any type. Values between variables can be swapped in two ways with help of a third (temp) variable without using any temporary variable #include <stdio.h> int main() { int x, j, temp; x = 13; j = 88; printf("Values before swapping - \n x = %d, j = %d \n\n", x, j); temp = x; x = j; j = temp; printf("Values after swapping - \n x = %d, j = %d \n", x, j); } procedure swap(x, j) set temp to 0 temp = x x = j // x holds value of j j = temp // j holds value of x stored in temp end procedure