In C++, one can assign default values to the formal parameters of a function prototype.
The Default arguments allows to omit some arguments when calling the function.
1. For any missing arguments, complier uses the values in default arguments for the called function.
2. The default value is given in the form of variable initialization.
Example : void defaultvalue(int n1 = 10, n2 = 100);
3. The default arguments facilitate the function call statement with partial or no arguments.
Example :
1. defaultvalue (x, y);
2. defaultvalue (200, 150);
3. defaultvalue (150);
4. defaultvalue (x, 150);
4. The default values can be included in the function prototype from right to left, i.e., we cannot have a default value for an argument in between the argument list.
Example:
1. void defaultvalue (int n1=10, n2);//invalid prototype.
2. void defaultvalue (int n1, n2 = 10);//valid prototype.