140k views
1 vote
a programmer defines the following: int calcroute(int x = -1, int y, int z) ... what is true for the following call: calcroute(2, 3)?

User Kprevas
by
8.4k points

1 Answer

5 votes

Final answer:

The function call calcroute(2, 3) results in a compile error because the third parameter 'z' is missing and does not have a default value set. Parameters with default values must be specified at the end of the parameter list.

Step-by-step explanation:

The student's question relates to a function declaration in programming, specifically concerning default parameter values in C++ functions. When the programmer defines the function with int calcroute(int x = -1, int y, int z), they are providing a default value for the first parameter 'x' only. This means that if the function is called without specifying the argument for 'x', it will automatically take the value of -1. However, the call calcroute(2, 3) specifies the first two parameters, and since default parameters must be the trailing parameters, this call will result in a compile error because the third parameter 'z' has not been provided and does not have a default value. A correct call to this function with two arguments would only be possible if the default value was assigned to the last parameter, for example, 'z'.

User Danielv
by
8.3k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.