click on this link......

LinkGrand.com
Showing posts with label call by reference. Show all posts
Showing posts with label call by reference. Show all posts

Thursday, 12 September 2013

Swapping of two numbers using call by reference

#include<stdio.h>
#include<conio.h>
void swap(int*,int*);
void main()
{
int a,b;
clrscr();
printf("\nEnter two nos: ");
scanf("%d%d",&a,&b);
printf("\nvalues before swapping: %d\t%d",a,b);
swap(&a,&b);
printf("\nvalues after swapping: %d\t%d",a,b);
getch();
}
void swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}

Output:
Enter two nos: 25 62
values before swapping: 25      62
values after swapping: 62    25