Pages

Thursday, March 27, 2014

C Program for passing value to a function by address

/*example of pass by address*/
#include<stdio.h>
#include<stdlib.h>
void swap (int *,int *);
int main()
{
    int a=5,b=9;
    printf("before swapping a=%d and b=%d",a,b);
    swap(&a,&b);
    printf("\n after swapping a=%d and b=%d",a,b);
    system ("pause");
    return 0;
}
void swap (int *x,int *y)
{
     int temp;
     temp=*x;
     *x=*y;
     *y=temp;
}

No comments:

Post a Comment