141k views
1 vote
The value of a default argument must be a(n) _________.

User DSent
by
6.5k points

1 Answer

1 vote

Answer:

Constant

Step-by-step explanation:

A default argument is a value provided in a function declaration that the compiler automatically assigns if the function caller does not provide a default value for the argument.

The value of a default argument must be constant.

The default value parameter must be a constant for compiling. Compiler does not accept dynamically calculated value against optional parameter. The reason behind this it is not certain that the dynamic value you provide would offer some valid value.

Example:

#include<iostream>

using namespace std;

/*A function with default arguments, it can be called upto 4 arguments*/

int sumnum(int x, int y, int z=0, int w=0)

{

return (x + y + z + w);

}

int main() //driver function

{

cout << sumnum(10, 15) << endl;

cout << sumnum(10, 15, 25) << endl;

cout << sumnum(10, 15, 25, 30) << endl;

return 0;

}

Output

25

50

80

User Praditha
by
6.6k points