added return type of main() (#18614)

- Add return type of main()
- Fix small formatting and add reference link
pull/18837/head^2
Shaurya Vardhan Singh 2018-10-16 02:04:54 +05:30 committed by Eric Leung
parent ab37bb5080
commit 1aafeb9859
1 changed files with 6 additions and 6 deletions

View File

@ -3,7 +3,7 @@ title: Functions in C++
---
## Definition:
A function is a group of statements that together perform a task. Every C++ program has at least one function, which is main().
A function is a group of statements that together perform a task. Every C++ program has at least one function, which is `main()`.
A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.
@ -17,7 +17,7 @@ return_type function_name( parameter list )
```
### Return type:
A function may return a value. The return_type is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the return_type is the keyword void.
A function may return a value. The `return_type` is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the `return_type` is the keyword `void`, but the [return type of main() must always be int](https://stackoverflow.com/a/4207223/).
### Function name:
This is the actual name of the function. The function name and the parameter list together constitute the function signature.
@ -47,12 +47,12 @@ int max(int num1, int num2)
## Why are functions important?
Functions support modularity(breaking down of work into smaller pieces called modules) which is an essential feature of 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.
Having specific functions to perform specific tasks removes confusion and shortens the length of the main function.
The function also performs reusability of code. So the next time you have to calculate the maximum of two different numbers agaun and again in the same program, you do not need to copy and paste your code. You just have to call the function and it does rest of the work.
The function also performs reusability of code. So the next time you have to calculate the maximum of two different numbers again and again in the same program, you do not need to copy and paste your code. You just have to call the function and it does rest of the work.
## More Information
* [TutorialsPoint](https://www.tutorialspoint.com/cplusplus/cpp_functions.htm)