diff --git a/content/cpp/functions.md b/content/cpp/functions.md index 26c9ff9..ba94075 100644 --- a/content/cpp/functions.md +++ b/content/cpp/functions.md @@ -34,3 +34,13 @@ int square(int x) { ``` Function abstraction is the ability to make a function easy to use without understanding exactly how the function works line by line. This makes it easy for other people to use your code faster. It is a good practice to make your code easy to use for other people. + +## Default arguments + +Suppose you want a function to occassionaly not have values for parameters explicitly define, you can set a default value for your parameters within your function. + +```c++ +void average(float num1 = 3, float num2 = 3, float num3 = 3); +``` + +In this example, the default parameters were create in the function prototype. Suppose you call the function by `average();`, then without passing and values, num1, num2, and num3 were all initialized with 3 as we have define in the prototype. Default arguments also work with just one parameter. You can set whatever parameter you want to have a default argument. Also, as long as the default argument is defined in the prototype, you should not include it in the definition.