C program to swap values of two variables using function (call by reference).

#include<stdio.h>
#include<conio.h>
void main(){
int a,b;
void swap(int*,int*);
clrscr();
printf("Enter two integer numbers\n");
scanf("%d%d",&a,&b);
printf("Before swapping A=%d and B=%d\n",a,b);
swap(&a,&b);
printf("After swapping A=%d and B=%d\n",a,b);
getch();
}
void swap(int *x,int *y){
int z;
z=*x;
*x=*y;
*y=z;
return;
}

No comments:

Post a Comment