c code for swapping

  • cswappingby value ,reference
  • how to swap in c using call by value and reference

    write a program to swap two integers using call by value and call by reference method by passing argument to the function.

    Code

    #include <stdio.h> #include <stdlib.h> #include <string.h> void callswap(int a ,int b){ int temp; temp = a; a = b; b = temp; } void refrenceswap(int *a ,int *b){ int temp; temp = *a; *a = *b; *b = temp; } int main(){ int x,y; printf("enter the two numbers to swap\n"); scanf("%d",&x); scanf("%d",&y); callswap(x,y); printf("the value of a and b are : %d and %d\n",x,y); refrenceswap(&x,&y); printf("the value of a and b are : %d and %d\n",x,y); return 0; }