Swap Two Numbers Using Pointer in C


Write a C program to swap the values of 2 integer variables “a” and “b” and display them.
Note : Use Pointers concept. [Dec 2015, Set-2]

#include<stdio.h>

void swap(int *, int *);

int main()
{
     int a=10,b=20;
     swap(&a, &b);
     printf("%d %d", a, b);
     return 0;
}

void swap(int *x, int *y)
{
     int t;
     t = *x;
     *x = *y;
     *y = t;
}