# 12. Integers

### Integer Types

* Integers are used to store natural numbers are 1,2,3.
* Go has 8 types on integers
* &#x20;`int8`, `int16`, `int32`, and `int64`, and corresponding unsigned versions `uint8`, `uint16`, `uint32`, and `uint64.`
* unsigned integers can store positive numbers only.
* 8,16,32 and 64 represents how many bits are used to store value.

| Bits | Signed                                                  | Unsigned                        |
| ---- | ------------------------------------------------------- | ------------------------------- |
| 8    | –128 to 127                                             | 0 to 255                        |
| 16   | –32,768 to 32,767                                       | 0 to 65535                      |
| 32   | –2,147,483,648 to 2,147,483,647                         | 0 to 4,294,967,295              |
| 64   | –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 0 to 18,446,744,073,709,551,615 |

### Declaring Integers

Integers are declared using one of the 3 ways:

{% code title="main.go" %}

```go
var j int32 = 20
var i int = 10
var i = 10
i := 10
var k int
```

{% endcode %}

If we are not specifying type like in 2nd and 3rd declaration, it will default to `int`

Zero value for integer is `0`

{% hint style="success" %}
Always use short declaration way when assigning initial value. If you wish to initialize a variable to its zero value, use var declaration.
{% endhint %}

### Using Test Driven Development for integers

Learn how to do test driven development when using integers from Chris

{% embed url="<https://github.com/quii/learn-go-with-tests/blob/master/integers.md>" %}


---

# Agent Instructions: 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:

```
GET https://book.codewithgo.com/integers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
