#include #include "prog3.h" /* This program illustrates how to get two values back from a function. * * Since functions can only return a single value, we must either get * the values back via parameters, or create a structure that contains * the two values. This program illustrates passing values back in * parameters. * * Note that C implements "pass by value" (known more informally as * pass by copy). That means that a copy of each value is passed. If * the function changes the parameter, it is only changing its own copy. * To simulate "pass-by-reference", we must pass the ADDRESS of the * variable whose value we wish to change. The address is passed by * value, but that's OK because we don't want to change the address, * we want to change the value AT that address. */ int main(int argc, char *argv[]) { int i; /* loop index variable */ int num1; /* num1 will be input from user */ int num2; /* num2 will be input from user */ /* Set num1 and num2 to arbitrary values to illustrate a point. */ num1 = 111; num2 = 222; /* Get two numbers. (This function is broken.) */ tryToGet2Nums(num1, num2); /* Print num1 and num2. */ printf("\n\tIn main: The user typed in %d and %d. (NOT!)\n\n\n", num1, num2); /* Get two numbers. (This function works.) */ get2Nums(&num1, &num2); /* Pass ADDRESSES of 2 variables. */ /* Print num1 and num2. */ printf("\n\tIn main: The user typed in %d and %d.\n\n\n", num1, num2); }