parent
bc32dc780b
commit
90c36b3c19
1 changed files with 27 additions and 6 deletions
@ -1,7 +1,28 @@ |
||||
# Functions |
||||
# 📘 Functions in C++ |
||||
|
||||
Functions in programming are named sections of a program that perform a specific task. They allow us to write a piece of code once and reuse it in different places throughout the program, making our code more modular and easier to maintain. Functions often take in input, do something with it, and return output. Functions can be categorized into four main types: |
||||
- **Built-in** functions: provided by the programming language, like `print()` in Python. |
||||
- **User-defined** functions: written by the user for a specific use case. |
||||
- **Anonymous** functions: also known as lambda functions, which are not declared using the standard keyword (`def` in Python, for example). |
||||
- **Higher-order** functions: functions that take other functions as arguments or return a function. |
||||
## 🔧 What is a Function? |
||||
|
||||
A **function** is a block of code that performs a specific task. It helps in: |
||||
|
||||
- **Code reusability** |
||||
- **Modular programming** |
||||
- **Improved readability and maintainability** |
||||
|
||||
--- |
||||
|
||||
## ✅ Why Use Functions? |
||||
|
||||
- Avoid code repetition |
||||
- Break large problems into smaller parts |
||||
- Easier debugging and testing |
||||
- Cleaner and more organized code |
||||
|
||||
--- |
||||
|
||||
## 🧱 Syntax of a Function |
||||
|
||||
```cpp |
||||
return_type function_name(parameters) { |
||||
// body of the function |
||||
return value; // optional if return_type is void |
||||
} |
||||
|
Loading…
Reference in new issue