> For the complete documentation index, see [llms.txt](https://ineelhere.gitbook.io/code-with-go/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ineelhere.gitbook.io/code-with-go/12-functions.md).

# Functions

This is a simple Go program that defines two functions for addition and demonstrates their usage in the main function.

```go
// Importing the "fmt" package, which provides functions for formatted I/O.
import "fmt"

// Function plus takes two integers (a and b) as parameters and returns their sum.
func plus(a int, b int) int {
    return a + b
}

// Function plusPlus takes three integers (a, b, and c) as parameters and returns their sum.
func plusPlus(a, b, c int) int {
    return a + b + c
}

// The main function, which serves as the entry point for the program.
func main() {
    // Calling the plus function with arguments 1 and 2, storing the result in the variable "res".
    res := plus(1, 2)
    
    // Printing the result of the addition operation.
    fmt.Println("1+2 =", res)

    // Calling the plusPlus function with arguments 1, 2, and 3, storing the result in the variable "res".
    res = plusPlus(1, 2, 3)
    
    // Printing the result of the addition operation.
    fmt.Println("1+2+3 =", res)
}
```

#### Output

```
1+2 = 3
1+2+3 = 6
```

Now, let's break down the code and explain each part:

1. **Function Declarations:**
   * `plus(a int, b int) int`: This function takes two integers (`a` and `b`) as parameters and returns their sum.
   * `plusPlus(a, b, c int) int`: This function takes three integers (`a`, `b`, and `c`) as parameters and returns their sum.
2. **Main Function:**
   * `main()`: This is the entry point of the program.
   * `res := plus(1, 2)`: Calls the `plus` function with arguments 1 and 2, and stores the result in the variable `res`.
   * `fmt.Println("1+2 =", res)`: Prints the result of the addition operation.
   * `res = plusPlus(1, 2, 3)`: Calls the `plusPlus` function with arguments 1, 2, and 3, and stores the result in the variable `res`.
   * `fmt.Println("1+2+3 =", res)`: Prints the result of the addition operation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ineelhere.gitbook.io/code-with-go/12-functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
