Add recursive function definition and example (#30714)

This commit is contained in:
Gourav
2019-03-27 06:46:37 +05:30
committed by Randell Dawson
parent 74cd81faf9
commit 82ff627738

View File

@@ -128,6 +128,23 @@ int val = test();
``` ```
## Recursive Function
When the function calls itself then it is known as recursive function.
Example:
```cpp
void printNumbersUptoN(int n)
{
if(n == 0)
return;
printNumbersUptoN(n - 1);
cout<<n<<endl;
}
```
## Why are functions important? ## Why are functions important?
Functions support modularity (breaking down of work into smaller pieces called modules), which is an essential feature of object-oriented programming (OOP) which primarily separates C++ from C. Functions support modularity (breaking down of work into smaller pieces called modules), which is an essential feature of object-oriented programming (OOP) which primarily separates C++ from C.