CODING-
//SWAPPING INTERCHANGE CALL BY VALUE
#include<stdio.h>
#include<conio.h>
void swap(int x, int y);
void main()
{
int a=10, b=20;
clrscr();
printf("A before swapping=%d\n",a);
printf("B before swapping=%d\n",b);
swap(a, b);
printf("X after swapping=%d\n",a);
printf("Y after swapping=%d\n",b);
getch();
}
void swap(int x, int y)
{
int c;
c=x;
x=y;
y=c;
printf("Value of x=%d\n y=%d\n",x,y);
}
OUTPUT-
A Before swapping=10
B before swapping=20
value of x=20
value of y=10
X after swapping=10
Y after swapping=20
//SWAPPING INTERCHANGE CALL BY VALUE
#include<stdio.h>
#include<conio.h>
void swap(int x, int y);
void main()
{
int a=10, b=20;
clrscr();
printf("A before swapping=%d\n",a);
printf("B before swapping=%d\n",b);
swap(a, b);
printf("X after swapping=%d\n",a);
printf("Y after swapping=%d\n",b);
getch();
}
void swap(int x, int y)
{
int c;
c=x;
x=y;
y=c;
printf("Value of x=%d\n y=%d\n",x,y);
}
OUTPUT-
A Before swapping=10
B before swapping=20
value of x=20
value of y=10
X after swapping=10
Y after swapping=20
Comments
Post a Comment
Please Subscribe and Comments my blog site.