Write a 'C' Program to swap the values of two variables by using call by reference.


#include

void swap(int *, int *);

void main()
{
    int a,b;
    clrscr();
    printf("ENTER TWO NUMBERS :: >\n");
    scanf("%d%d",&a,&b);
    printf("BEFORE SWAPING :: > A = %d B = %d\n",a,b);
    swap(&a,&b);
    printf("AFTER  SWAPING :: > A = %d B = %d",a,b);
    getch();
}
void swap (int *x,int *y)
{
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}
/*OUTPUT::
ENTER TWO NUMBERS :: >
2 4
BEFORE SWAPING :: > A = 2 B = 4
AFTER  SWAPING :: > A = 4 B = 2

ENTER TWO NUMBERS :: >
10 20
BEFORE SWAPING :: > A = 10 B = 20
AFTER  SWAPING :: > A = 20 B = 10
*/
Write a 'C' Program to swap the values of two variables by using call by reference. Write a 'C' Program to swap the values of two variables by using call by reference. Reviewed by on April 24, 2015 Rating: 5
Powered by Blogger.