Swap Numbers call by value and refrence
#include<stdio.h>
#include<conio.h>
void swap1(int x,int y)
{
int z;
z=x;
z=y;
y=z;
printf("x = %d and y = %d",x,y);
}
void swap2(int *p , int *q)
{
int c;
c=*p;
*p=*q;
*q=c;
printf("x = %d and y = %d",*p,*q);
}
void main()
{
int a,b;
clrscr();
a=5;
b=7;
swap1(a,b);
printf("After Swap1 Value of a = %d and b = %d \n",a,b);
swap2(&a,&b);
printf("After swap2 value of a = %d and b = %d",a,b);
getch();
}
#include<conio.h>
void swap1(int x,int y)
{
int z;
z=x;
z=y;
y=z;
printf("x = %d and y = %d",x,y);
}
void swap2(int *p , int *q)
{
int c;
c=*p;
*p=*q;
*q=c;
printf("x = %d and y = %d",*p,*q);
}
void main()
{
int a,b;
clrscr();
a=5;
b=7;
swap1(a,b);
printf("After Swap1 Value of a = %d and b = %d \n",a,b);
swap2(&a,&b);
printf("After swap2 value of a = %d and b = %d",a,b);
getch();
}
Post a Comment