Swap Value By Call By Reference - C Program

Swap Value By Call By Reference

 #include <stdio.h>
void swap(int *a,int *b);
int main()
{
	int x,y;
	
	printf("Enter the value of x and y :");
	scanf("%d%d",&x,&y);
	swap(&x,&y);
	printf("After swapping x=%d y=%d",x,y);
	
	return 0;
}
void swap(int *a,int *b)
{
	int c;
	c=*a;
	*a=*b;
	*b=c;
}

Output - Swap Value By Call By Reference

Enter the value of x and y :10 20                                                                                     
After swapping x=20 y=10
Compile and Run Online