---
title: "Comment by Purvi Barot on \"Why use functions?\" | Hashnode"
description: "A function is a group of statements that together perform a specific task. You can write all intended functionality at one place and call it wherever required."
url: "https://hashnode.com/posts/why-use-functions/603136f372a689446db3df14/comment/603734bc05efef7f0a9d4507"
---

[Discussion](https://hashnode.com/posts/why-use-functions/603136f372a689446db3df14)

Comment [Why use functions?](https://hashnode.com/posts/why-use-functions/603136f372a689446db3df14)

[Purvi Barot](https://hashnode.com/@purvi)

[Feb 25, 2021](https://hashnode.com/posts/why-use-functions/603136f372a689446db3df14/comment/603734bc05efef7f0a9d4507)

A function is a group of statements that together perform a specific task. You can write all intended functionality at one place and call it wherever required.

**Why use function ?**

Function are used for divide a large code into module, due to this we can easily debug and maintain the code. For example if we write a calculator programs at that time we can write every logic in a separate function (For addition sum(), for subtraction sub()). Any function can be called many times.

**Defining a function:**

```
return_type  function_name(parameter) 
{ 
function body; 
}
```

**Calling a function:**

```
function_name();  
OR   
variable=function_name(argument);
```

**Advantage of Function:**

-   Code Re-usability
-   Develop an application in module format.
-   Easily to debug the program.
-   Code optimization: No need to write lot of code.
-   Length of the source code can be reduced.
