31.6k views
0 votes
When a function is called, how are parameters and arguments (formal and actual parameters) matched up?

A) Parameters are matched with actual parameters based on their order in the function call.
B) Parameters are matched with actual parameters based on their names in the function call.
C) Parameters are matched with actual parameters randomly in the function call.
D) Parameters and actual parameters are not matched up in the function call.

User Yevhenii
by
8.5k points

1 Answer

2 votes

Final answer:

A) Parameters are matched with actual parameters based on their order in the function call.Parameters and arguments are matched up based on their order in the function call.

Step-by-step explanation:

When a function is called, parameters and arguments are matched up based on their order in the function call. This means that the first parameter in the function definition will be matched with the first argument in the function call, the second parameter with the second argument, and so on. This is known as matching parameters and arguments by position. This is known as matching parameters and arguments by position.

For example, consider the following function definition:

void foo(int a, double b) {
// function body
}

If we call this function as foo(5, 3.14), the value 5 will be matched with the parameter a and the value 3.14 will be matched with the parameter b.

User Kundan Chaudhary
by
8.0k points