Default arguments
One of the useful facilities available in C++ language is the facility to define default argument values for the functions. Within the function prototype declaration, the default value is given. Whenever a call is made to a function without specifying an argument in which the program will automatically assign values to the parameters from the default function prototype declaration. Default arguments facilitate make simple development and maintenance of programs.
Sample program
// default argument declaration
# include <iostream.h>
void sum (int a, int b, int c = 6, int d = 10); //default argument initialization
void main( void)
{
int a,b,c,d;
cout<<"enter any two numbers\n";
cin>>a>>b;
sum(a,b); //sum of default values
}
void sum(int a1, int a2, int a3, int a4)
{
int temp;
temp = a1+a2+a3+a4;
cout<< "sum="<< temp;
}
output of the above program
enter any two numbers
10 20
sum = 46