Write a ‘C’ program to swap the values of two variables by using call by reference.

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c;
clrscr();
printf("Enter the value of a & b:\n");
scanf("%d%d",&a,&b);
printf("A=%d\n\nB=%d",a,b);
swap(&a,&b);
printf("\nA=%d\nB=%d\n",a,b);
getch();
}

swap(int*x,int*y)
{
*x=*x+*y;
*y=*x-*y;
*x=*x-*y;
return;
}

Comments