/* params.cpp provides an experimental setting
 * for exploring reference parameters.
 *
 * Begun by: Adams, for Hands On C++.
 * Completed by:
 * Date:
 *
 * Specification:
 * output(screen): the values of 3 variables, int1, int2, int3,
 ***************************************************************/

//Hypothesis 4a: I think that an error will occur because the amount paramters is different than the amount of arguments.
//Hypothesis 4b: I think that an error will occur for a similar reason, the number of parameters and arguments is different and it won't be able to link the two together.

#include <iostream>
using namespace std;

void Change(int, int, int);

int main() {
    // 0. Print a message explaining the program;
    cout << "\nThis program provides a 'laboratory' in which\n"
         << "experiments can be performed on parameter-passing.\n";

    int arg1, arg2, arg3;

    // 1. Initialize arguments to -1;
    arg1 = arg2 = arg3 = -1;

    // 2. Display Arg1, Arg2, and Arg3 (before Change);
    cout << "\nBefore: arg1 = " << arg1 << ", arg2 = " << arg2 << ", arg3 = " << arg3 << endl;

    // 3. Call Change, passing it Arg1, Arg2, and Arg3 are arguments;
    Change(arg1, arg2, arg3);

    // 4. Display Arg1, Arg2, and Arg3 (following Change);
    cout << "\nAfter: arg1 = " << arg1 << ", arg2 = " << arg2 << ", arg3 = " << arg3 << "\n\n";

    /*
     * Hypothesis:
     * It is permissible to assign a value to a value parameter, but this only
     * changes the local copy within the function, not the original argument
     * in main(). Therefore, the values of arg1, arg2, and arg3 will NOT be
     * changed after the call to the Change function; they will remain -1.
     */
}

/*************************************************************************
 * Change is the 'lab' in which we experiment with parameter passing.
 *
 * Specification:
 * receive(caller): 3 integers, stored in Param1, Param2, Param3;
 * return(caller): the (altered ???) values of Param1, Param2, Param3.
 *************************************************************************/
void Change(int param1, int param2, int param3, int param4) {
    param1 = 1;
    param2 = 2;
    param3 = 3;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: