Program:

#include<stdio.h>
int swap(int *a, int *b)
{
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}
int main(){
    int x = 20, y = 50;
    printf("Before Swap: x= %d y= %d", x, y);
    swap(&x, &y);
    printf("\nAfter Swap: x= %d y= %d\n", x, y);
}

Output:

Before Swap: x = 20  y = 50 
After Swap:  x = 50  y = 20 

Leave a Reply

Your email address will not be published. Required fields are marked *