Write a program to perform swapping two numbers using call by reference.

#include<stdio.h>
#include<conio.h>
void swap(int *,int *);
int main()
{
int a,b;
printf("enter the value of a");
scanf("%d",&a);
printf("enter the value of b");
scanf("%d",&b);
printf("the value of a before swapping is %d",a);
printf("\nthe value of b before swapping is %d",b);
swap(&a,&b);
printf("\nthe value of a after swapping is %d",a);
printf("\nthe value of b after swapping is %d",b);
}
void swap(int *p1,int *p2)
{
int temp;
temp=*p2;
*p2=*p1;
*p1=temp;
}

No comments:

Post a Comment