A default argument is a part of function declaration (not definition - in function definition, it must always be provided). It instructs the compiler what value to pass for an argument if the programmer deliberately misses the argument when calling a function.
As a reasonable example, suppose we define a function which parses a text string to extract an integer value; that is, converting "123" to 123. The function definition is like:
int parseInt (string numberText, int radix)
{
//...
}
Here, the second parameter is the radix of conversion: 2, 8, 10, 16. This function assumes that this value is provided and uses it as the radix of the number.
However, in declaration, you could assume that the default radix is 10 (the value taken if not explicitly given by user) and declare it as:
int parseInt (string numberText, int radix = 10);
This instructs the compiler that the programmer could deliberately not give the second argument (radix) in which case, the compiler should assume radix = 10. In other words, the programmer writes the code like:
int value = parseInt ("22331");
and the compiler would convert it to
int value = parseInt ("22331", 10);
automatically before translating it to the machine code.
A final important note is that a default argument must be provided such that it does not produce ambiguity with already existing function overloads. As an example, suppose we have max () functions which returns the maximum number of the given arguments:
max (int a, int b); // returns the maximum of a and b.
max (int a, int b, int c); // returns the maximum of a, b and c.
Here we cannot make the argument c of the second function as a default parameter:
max (int a, int b, int c = INT_MIN); // returns the maximum of a, b and c (if present).
if max (int, int) has not been defined as overload, this function, max (int,int,int), would return the maximum of a and b because, with c = INT_MIN, c would always lose all competitions, and actually only a and b are compared.
But since the overload max (int,int) does exist, the default argument has some ambiguity and incurs compiler error:
cout << max (20, 25); // trouble
which overload? max (int, int) or max (int, int, int) with default INT_MIN?