swaping value by using pointers in c
#include<stdio.h>
int swap ( int *a, int *b);
int main()
{
int x = 3, y = 4;
printf("The value of x and y before swap is %d and %d\n", x, y);
swap(&x,&y);//will work due to call by reference
printf("The value of x and y after swap is %d and %d\n", x, y);
return 0;
}
int swap ( int *a, int *b){
int temp;
temp = *a;
*a = *b;
*b = temp;
}
Comments
Post a Comment