source file name: SwapPtr.C
void swap1(int a, int b) // call by value function
{
int t=a;
a=b;
b=t;
printf("\n inside swap1 function values are X=%d and Y=%d", a,b);
}
void swap2(int *a, int *b) // call by pointer function
{
int t=*a;
*a=*b;
*b=t;
printf("\n inside swap2 function values are C=%d and D=%d", *a,*b);
}
void main()
{
int x,y;
int c,d;
clrscr();
printf("Interchange of two variables program");
printf("\n enter 2 numbers C and D: ");
scanf("%d%d",&c,&d);
printf("\n enter 2 numbers X and Y ");
scanf("%d%d",&x,&y);
swap1(x,y); // call by value function
swap2(&c,&d); // call by reference or pointer
printf("\n after interchange values are X=%d and Y=%d", x,y);
printf("\n after interchange values are C=%d and D=%d", c,d);
getch();
}
output:
0 Comments
Post a Comment