This commit is contained in:
lucasrufkahr
2026-03-02 14:41:27 -06:00
parent 48746c973c
commit 91628c023e

View File

@@ -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.