/* * Program to illustrate pass by reference / pointers. */ #include /* * Prompt user for two numbers and put in locations supplied by * caller. Parameter z illustrates what happens when parameters * are passed directly rather than using pointers. */ int get_two_numbers(int *a, int *b, int z) { /* as done in class int aa = 0, bb = 0, return_val; printf("enter two numbers\n"); return_val = scanf("%d %d", &aa, &bb); *a = aa; *b = bb; z = 50; return return_val; */ /* shorter way */ z = 50; printf("enter two numbers\n"); return scanf("%d %d", a, b); } /* * Main program. */ int main(void) { int x, y, z; if (get_two_numbers(&x, &y, z) == 2) { printf("AOK %d %d %d\n", x, y, z); } else { printf("error\n"); } return 0; }