Go Language Data Types
In the Go programming language, data types are used to declare functions and variables.
The purpose of data types is to categorize data into different sizes of memory required for storage. This allows programmers to allocate larger memory only when needed for large data, thereby making efficient use of memory.
Go language has the following data types categorized by class:
No. | Type and Description |
---|---|
1 | Boolean <br>Boolean values can only be constants true or false. Example: var b bool = true. |
2 | Numeric Types <br>Integers int and floating-point numbers float32, float64. Go supports integers and floating-point numbers and also supports complex numbers, with bit operations using two's complement. |
3 | String Types: <br>A string is a sequence of characters of fixed length. Go strings are made up of individual bytes. Go language strings use UTF-8 encoding for Unicode text. |
4 | Derived Types: <br>Includes: (a) Pointer Type (Pointer) (b) Array Type (c) Structured Type (struct) (d) Channel Type (e) Function Type (f) Slice Type (g) Interface Type (interface) (h) Map Type |
Numeric Types
Go also has architecture-based types such as int, uint, and uintptr.
No. | Type and Description |
---|---|
1 | uint8 <br>Unsigned 8-bit integer (0 to 255) |
2 | uint16 <br>Unsigned 16-bit integer (0 to 65535) |
3 | uint32 <br>Unsigned 32-bit integer (0 to 4294967295) |
4 | uint64 <br>Unsigned 64-bit integer (0 to 18446744073709551615) |
5 | int8 <br>Signed 8-bit integer (-128 to 127) |
6 | int16 <br>Signed 16-bit integer (-32768 to 32767) |
7 | int32 <br>Signed 32-bit integer (-2147483648 to 2147483647) |
8 | int64 <br>Signed 64-bit integer (-9223372036854775808 to 9223372036854775807) |
Floating-Point Types
No. | Type and Description |
---|---|
1 | float32 <br>IEEE-754 32-bit floating-point number |
2 | float64 <br>IEEE-754 64-bit floating-point number |
3 | complex64 <br>32-bit real and imaginary numbers |
4 | complex128 <br>64-bit real and imaginary numbers |
Other Numeric Types
Here are some other numeric types:
No. | Type and Description |
---|---|
1 | byte <br>Similar to uint8 |
2 | rune <br>Similar to int32 |
3 | uint <br>32 or 64 bits |
4 | int <br>Same size as uint |
5 | uintptr <br>Unsigned integer to store a pointer |