C examples for Pointer:Pointer Variable
#include <stdio.h> void sort_variables(double *x, double *y, double *z); int main(void) { double x, y, z; printf("Enter three numbers x, y and z:\n"); while(scanf("%lf %lf %lf", &x, &y, &z) == 3) {/*from w w w . ja va 2s . c o m*/ putchar('\n'); printf("Before calling sort_variables:\n"); printf("x = %f, y = %f, z = %f\n", x, y, z); sort_variables(&x, &y, &z); putchar('\n'); printf("After calling sort_variables:\n"); printf("x = %f, y = %f, z = %f\n", x, y, z); putchar('\n'); printf("Enter three numbers x, y and z:\n"); } return 0; } void sort_variables(double *x, double *y, double *z) { double tmp; if (*x > *y) { // switch x and y tmp = *y; *y = *x; *x = tmp; } if (*y > *z) { // switch y and z tmp = *z; *z = *y; *y = tmp; if (*x > *y) { // switch x and y tmp = *y; *y = *x; *x = tmp; } } }