Functions Summary
In this chapter, we learned to work with functions in C++. We discovered that:
- We use functions when we want to group repetitive code or solve a specific problem.
- We define a function by specifying the return type, followed by the function name and parentheses.
- Every function must have a specified return type (e.g.,
void
for functions that don't return anything). - The function body contains the code that executes when the function is called, enclosed in curly braces.
- We call a function using its name followed by parentheses.
- We can only call a function after its declaration.
- Functions can accept parameters that influence their behavior.
- For each parameter, we must specify its data type.
- Function parameters can have default values, which are used if no parameter value is provided when calling the function.
- Functions can return values using the
return
keyword. The returned value must match the declared return type. - Every C++ program must contain a
main
function that returnsint
.
Instructions
Congratulations on completing the C++ course! Now just practice and combine the concepts you've learned and you'll be surprised what you can program!
Start programming for free
7/7