Example: #1 - Swapping of two numbers using temporary variable
C Input Screen
#include<stdio.h>
int main(int argc, const char * argv[])
{
int a = 3;
int b = 6;
printf("The value of a before swap is %d \n", a);
printf("The value of b before swap is %d \n", b);
// Swapping of two numbers using temp variable
int temp = a;
a = b;
b = temp;
printf("The value of a after swap is %d \n", a);
printf("The value of b after swap is %d \n", b);
}
C Output Screen
The value of a before swap is 3
The value of b before swap is 6
The value of a after swap is 6
The value of b after swap is 3