Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit C++ functions file #5521

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion content/cpp/concepts/functions/functions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
Title: 'Functions'
Description: 'A function is a set of statements that are executed together when the function is called. Every function has a name, which is used to call the respective function. C++ has many built-in functions.'
Description: 'Functions are self-contained blocks of code designed to perform specific tasks, allowing for code reuse and modularity.'
Subjects:
- 'Computer Science'
- 'Game Development'
Expand Down Expand Up @@ -183,3 +183,32 @@ This will output:
When add function is called with integer parameters: 20
When add function is called with string parameters: HelloWorld!
```

## Recursion

Recursion is a technique that allows a function to call itself. In C++, the function that calls itself is called a recursive function:

```cpp
#include <iostream>
using namespace std;

int sum(int m) {
if (m > 0) {
return m + sum(m - 1); // Recursive call
} else {
return 0; // Base case
}
}

int main() {
int result = sum(5);
cout << result;
return 0;
}
```

This program will output the following result:

```shell
15
```
Loading