Skip to main content

C Program To Swap Two Numbers Using Pointer.

#include<stdio.h>

void swap(int *num1, int *num2) {
int temp; 
temp = *num1;

*num1 = *num2; 
*num2 = temp; }

int main() {
int num1, num2;

printf("Enter the value of x and y: ");
scanf("%d%d", &num1, &num2);

printf("\nBefore Swapping\nx = %d\ny = %d\n",num1,num2);
swap(&num1, &num2);

printf("\nAfter Swapping\nx = %d\ny = %d\n",num1,num2);
return 0;
}