Multiple choice

State whether the following function declaration with default values is valid or not? int sum (int a=10,int b);

  1. Valid

  2. Invalid

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In C++, default arguments must be specified from right to left. If a parameter has a default value, all parameters to its right must also have default values. Here, parameter 'a' has a default value but parameter 'b' (to its right) does not, making this declaration invalid.