Using a function to interchange the contents of two variables & Illustrates parameter pass by reference.

#include <stdio.h>

void swap(int *aptr, int *bptr);

int main(void)
{
int a, b ;

printf( "\nEnter values for a, b : " );
scanf("%d%d", &a, &b);

printf( "\nBefore swapping a = %d b = %d", a, b );
swap(&a, &b);
printf( "\nAfter swapping a = %d b = %d", a, b );

return 0;
}

void swap(int *aptr, int *bptr)
{
int x;

x = *aptr;
*aptr = *bptr;
*bptr = x;
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin