In this experiment, we will answer two different questions.
Question 4a: What happens if the number of arguments does not match the number of parameters in the function prototype?
Hypothesis: Using your experience and intuition, construct a hypothesis
(a statement that answers the question) in the space below.
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)If this is permitted, then no errors will be generated when we translate the program.
Observation: Translate your source program. What is displayed ?
Conclusions:
When the number of parameters in the prototype is different from the number of arguments in the function call, a compilation error results.
Restore the prototype to its original form, and then continue.
Question 4b: What happens if the number of arguments does not match the number of parameters in the function definition?
Hypothesis: Using your experience and intuition, construct a hypothesis
(a statement that answers the question) in the space below.
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;
}
If this is permitted, then no errors will be generated when we
translate the program.
Observation: Translate your source program. What is displayed?
How does it differ from what was displayed when we modified the prototype?
Conclusions:
When the number of parameters in the prototype is different from the number of arguments in the function call, a linking error results. The compiler checks the validity of a function call using the prototype, and so the program compiles correctly. However the program fails to link because the linker cannot find a function definition that matches the prototype.
Restore the definition to its original form and then continue.
Forward to the Next Experiment