Example:
void foo(int a,int b=12) {
...
}
Since which version of C++ is this legal? Was it introduced in C++11?
Generally no, but in gcc You may make the last parameter of funcA() optional with a macro.
A default argument is a value provided in a function declaration that is automatically assigned by the compiler if the calling function doesn't provide a value for the argument. In case any value is passed, the default value is overridden.
By default, C uses call by value to pass arguments.
In C++ programming, we can provide default values for function parameters. If a function with default arguments is called without passing arguments, then the default parameters are used. However, if arguments are passed while calling the function, the default arguments are ignored.
Per Bjarne's "History of C++" (see page 6), default arguments were added in the very first version of the very first incarnation of C++, C With Classes, whose "spec" (if you can call it that) was published back in 1980.
They remained present through to initial standardisation in 1998, and remain present to this day.
In other words, every version of C++ since the dawn of time has supported default arguments.
In other words: literally forever. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With