Practice mode C++

Which C++ function declaration is INVALID because of its default argument?

Correct answer C. void f(int a = 1, int b);

Explanation

In a function declaration, once a parameter has a default argument, every parameter after it must also have one (or receive one from an earlier declaration). void f(int a = 1, int b) breaks this rule, because b has no default after a defaulted parameter. The rule exists because arguments are matched from left to right, so callers can only omit trailing arguments.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.