#include "prog4.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 * a structure. * * 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 */ TwoNums aStruct; /* a structure containing 2 ints */ /* Set num1 and num2 to start with. */ aStruct.num1 = 111; aStruct.num2 = 222; /* Print num1 and num2. */ printf("\n\tIn main: The initial numbers are %d and %d.\n\n\n", aStruct.num1, aStruct.num2); /* Get two numbers. */ fill2Nums(&aStruct); /* Pass ADDRESS of aStruct. */ /* Print num1 and num2. */ printf("\n\tIn main: The user typed in %d and %d.\n\n\n", aStruct.num1, aStruct.num2); }