# Lab 8: Experiment 4

## Differing Numbers of Parameters and Arguments

You did change your code back after the previous exercise, right?

In this experiment, we will address two issues.

Issue A: What happens if the number of arguments in a function call does not match the number of parameters in the function prototype?

Hypothesis: The number of parameters in a prototype and the number of arguments in a function call does matter; the two numbers should be the same.

The Experiment: In the prototype of function `change()`, add a fourth parameter so that the number of parameters differs from the number of arguments.

`void change(int, int, int, int)`
Again, the compiler is in charge of this.

Question #8.4.1: What will the compiler do if it doesn't like this?

Question #8.4.2: What happens? Be specific.

Conclusions:

Question #8.4.3: Is our hypothesis correct? How do you know? If it's not correct, what should it be?

Restore the prototype to its original form, and then continue.

Issue B: What happens if the number of arguments does not match the number of parameters in the function definition?

Hypothesis: The number of parameters in a function definition and the number of arguments in a function call does matter; again, these two numbers must be the same.

The Experiment:

In the definition of function `change()`, add a fourth parameter so that the number of parameters differs from the number of arguments:

```void change(int param1, int param2, int param3, int param4)
{
param1 = 1;
param2 = 2;
param3 = 3;
}```

Make sure that you've restored your prototype so that it has only three parameters.

Question #8.4.4: What happens? Be specific.

Question #8.4.5: How is this result different from the results of changing the prototype? They are different, and understanding this difference will help you in debugging your code.

Conclusions:

Question #8.4.6: Is our hypothesis correct? How do you know? If it's not correct, what should it be?

Restore the definition to its original form and then continue.

Back to the Lab Exercise  |  Forward to the Next Experiment