C examples for Function:Function Parameter
Use pointer to exchange the values of the two variables
#include <stdio.h> void swap(int *x, int *y); int main(void) { int i, j;/* ww w.j a va 2 s .co m*/ i = 10; j = 20; printf("i and j before swapping: %d %d\n", i, j); swap(&i, &j); /* pass the addresses of i and j */ printf("i and j after swapping: %d %d\n", i, j); return 0; } void swap(int *x, int *y) { int temp; temp = *x; /* save the value at address x */ *x = *y; /* put y into x */ *y = temp; /* put x into y */ }