/* This program demonstrates pointers to various types */ #include /* Swap the values of the variables pointed to by pa and pb. By using pointers parameters, this effectively renders the parameter passing "by reference". */ void swap(int *pa, int *pb) { int temp = *pa; *pa = *pb; *pb = temp; } int main() { int x, y; int *pa, n; x = 1; y = 2; /* prints original values of x and y */ printf("x = %d, y = %d\n", x, y); swap(&x, &y); /* prints current values of x and y after swapping */ printf("x = %d, y = %d\n", x, y); n = 5; printf("n = %d\n", n); pa = &n; /* pa is now pointing to the n, so *pa is equal to n, which is 5 in this case */ printf("*pa = %d\n", *pa); /* we now change the value pointed to by pa to 6 */ *pa = 6; printf("*pa = %d\n", *pa); /* now the value of n is 6, since pa points to n */ printf("n = %d\n", n); return 0; }