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

#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);
//actual arguments will not change.
printf("A=%d and B=%d\n",a,b);
getch();
}
void swap(int x,int y){
int z;
z=x;
x=y;
y=z;
printf("After swapping A=%d and B=%d\n",x,y);
return;
}

No comments:

Post a Comment