C Program to swap the values of two variables by using call by reference

How to write a c program to swap the values of two variables by using call by reference in C Programming Language ?


Solution:
/*C Program to swap the values of two variables by using call by reference*/

#include<stdio.h>
#include<conio.h>
  void swap(int *,int *);
  void main()
{
  int a,b,c;
  clrscr();
  printf("\nEnter the value of A & B:\n");
  scanf("%d%d",&a,&b);
  printf("\nBefore swapping values:");
  printf("\n\tA=%d\n\tB=%d",a,b);
  swap(&a,&b);
  printf("\nAfter swapping values:");
  printf("\n\tA=%d\n\tB=%d\n",a,b);
  getch();
}
   void swap(int *x,int *y)
{
   int z;
  z=*x;
  *x=*y;
  *y=z;
  return(0);
}

//OUTPUT:
//Enter the value of A & B:10 20
//Before swapping values:
     //A=10
     //B=20
//After swapping values:
     //A=20

     //B=10


Learn More :