Develop a function in C that will swap (exchange) the value of two integer variables passed as arguments. Also write the main program.

#include <stdio.h>

void swap(int *x, int *y){
    *x = *x + *y;
    *y = *x - *y;
    *x = *x - *y;
}

int main(){
  int num1, num2;
 
  printf("Enter two integers: ");
  scanf("%d %d", &num1, &num2);
 
  printf("Before function call: num1 = %d and num2 = %d\n", num1, num2);
 
  swap(&num1, &num2);
 
  printf("After function call: num1 = %d and num2 = %d\n", num1, num2);
 
  return 0;
}

Comments