Menu

Tuesday, 23 June 2015

Pass by reference using functions



#include<stdio.h>
void fnswap(int *a,int *b);
main()
{
    int no1,no2;
    printf("Enter two numbers: ");
    scanf("%d %d",&no1,&no2);
    printf("\n Before swap no1 = %d and no2 = %d",no1,no2);
    fnswap(&no1,&no2);
    printf("\n After swap no1 = %d and no2 = %d",no1,no2);
}
void fnswap(int *x,int *y)
{
    int temp;
    temp=*x;
    *x=*y;
    *y=temp;
}

OUTPUT
Enter two numbers:89
58
Before swap no1 = 89 and no2 = 58
After swap no1 = 58 and no2 = 89