Back

#include<stdio.h>


void swap1(int a, int b);
void swap2(int *px, int *py);

int main()
{
int x=10, y=5, a=20, b=40;
int *px,*py;
px=&x;   py=&y;

printf("Let us Swap1 using pass by value...\n");
printf("Before a=%d   b=%d \n",a,b);
swap1(a,b);
printf("After a=%d   b=%d  \n",a,b);

printf("Let us Swap2 using pass by reference...\n");
printf("Before x=%d   y=%d \n",x,y);
swap2(&x,&y);
printf("After x=%d  y=%d \n",x,y);

return 0;
}

void swap1(int a, int b)
{
  int temp;
temp=a;
a=b;
b=temp;
}

void swap2(int *px, int *py)
{
  int temp;
temp=*px;
*px=*py;
*py=temp;
}

Top