Default Arg.

Is this the correct definition of default arguments?
A default argument is a value provided in function declaration that is automatically assigned by the compiler if caller of the function doesn’t provide a value for the argument with default value. They are passed to parameters automatically if no arg. is provided in function call.

Also, can someone give me an example of a call using default arguments and the header of the function called.

Is this a good example:
1
2
3
4
5
6
7
int mul(int ra=3, int rb=4);
    {  return ra*rb;  }
int main()
    {  cout << mul() << endl;
       cout << mul(5) << endl; 
       cout << mul(5,6) << endl; 
       return 0;   }
Last edited on
Line 1 is correct for a function declaration with default arguments.

However, you're missing function definition line.

1
2
3
4
int mul (int ra=3, int rb=4);  // Function declaration with default arguments

int mul (int ra, int rb);  // Function definition.  Defaults are NOT specified here.
{  return ra*rb;  }

Topic archived. No new replies allowed.