Types of data in Go
By
Darío Rivera
Posted On
in
Go
In a previous post we have seen Functions in Go. The next step is to see what types of data exist in this language in order to create all kinds of programs, functions and operations on these types. The following table presents all the basic data types, their description, size and range.
Type | Description | Size (bytes) | Range |
---|---|---|---|
bool | Booleans | true or false | |
string | Sequence of characters | N/A | |
int8 | Small integer numbers | 1 | -128 to 127 |
uint8/byte | Small unsigned integer numbers | 1 | 0 to 255 |
int16 | Integer numbers (small range) | 2 | -32,768 to 32,767 |
uint16 | Unsigned integer numbers (small range) | 2 | 0 to 65,535 |
int32/rune | Integer numbers | 4 | -2,147,483,648 to 2,147,483,647 |
uint32 | Unsigned integer numbers | 4 | 0 to 4,294,967,295 |
int64 | Integer numbers (larger range) | 8 | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
uint64 | Unsigned integer numbers (larger range) | 8 | 0 to 18,446,744,073,709,551,615 |
int | Integer numbers | ? | ? |
uint | Unsigned integer numbers | ? | ? |
uintptr | Integer type large enough to hold the bit pattern of any pointer | ? | ? |
float32 | Floating point numbers | 4 | +/-3.4 x 10^38 |
float64 | Higher precision floating point numbers | 8 | +/-1.7 x 10^308 |
complex64 | Complex numbers with float32 real and imaginary part | ||
complex128 | Complex numbers with float64 real and imaginary part |
The special types int
, uint
and uintptr
usually take 32-bit ranges on 32-bit systems or 64-bit ranges on 64-bit systems. It is advisable to use these types whenever possible and not fixed-size integer types. Throughout this series of posts we will see an example of use of each of the data types described above. See you soon!