WAP to implement a function that swaps two numbers using call by reference.
#include<stdio.h>
#include<conio.h>
void swap(int*,int*);
void main()
{
int a,b;
clrscr();
printf("\n Enter two numbers :\n");
scanf("%d%d",&a,&b);
printf("\n Before swapping a = %d and b = %d",a,b);
swap(&a,&b);
printf("\n After swapping a = %d and b = %d",a,b);
getch();
}
void swap(int *m,int *n)
{
int *t;
*t=*m;
*m=*n;
*n=*t;
}
Output:
Enter two numbers:
10
20
Before swapping a = 10 and b = 20
After swapping a = 20 and b = 10


0 Comments