31 January 2022

Call By Reference

 #include<stdio.h>

int swap(int *a, int *b);

int main()
{
    int x = 4, y = 8;
    printf("The value of x and y before swap is : %d and %d\n", x,y);
    swap(&x,&y);
    printf("The value of x and y before swap is : %d and %d\n", x,y);

return 0;
}
int swap(int *a, int *b){
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

OUT PUT--->

The value of x and y before swap is : 4 and 8 The value of x and y before swap is : 8 and 4


No comments:

Post a Comment