swap two numbers by their reference

Step Execution

#include <stdio.h>
void swap(int*, int*);
int main()
{
int x, y;
printf("Enter the first value\n");
scanf("%d",&x);
printf("Enter the second value\n");
scanf("%d",&y);
printf("Before Swapping\nx = %d", x);
printf("Before Swapping\ny = %d", y);
swap(&x, &y);
printf("After Swapping\nx = %d",x);
printf("After Swapping\ny = %d",y);
return 0;
}
void swap(int *a, int *b)
{
int temp;
temp = *b;
*b = *a;
*a = temp;
}

Initialize



Output

After swapping