Write a program to swap two nos.
using call by value and call by reference.
#include<stdio.h>
#include<conio.h>
int swapr(int *,int *);
int swapv(int x,int y);
int main()
{
int a=10,b=20;
clrscr();
swapr(&a,&b);
printf("\na=%d
b=%d",a,b);
swapv(a,b);
printf("\na=%d
b=%d",a,b);
}
int swapr(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
int swapv(int x,int y)
{
int t;
t=x;
x=y;
y=t;
printf("\nx=%d
y=%d",x,y);
}
Output