Tutorialsteacher

Follow Us

Go Data Types

In Go, built-in data types are categorized as below:

  • Basic types: boolean, numeric, string
  • Reference types: pointers, slices, maps, and channels
  • Aggregate or non-reference types: Arrays and structs
  • Interface types

Boolean

Boolean is a 1 bit type with either true or false value. The default value of boolean variable is false.

String

A string data type is the sequence of UTF-8 encoded characters with a definite length used to represent a text. It is declared by enclosing between double quotes or back quotes e.g. "Hello" and 'Hello' are strings in go.

Numeric types

Numeric types can be signed integers, unsigned integers, and floats.

Signed integers can store positive or negative numeric values. The following table lists signed integer types:

TypeSizeRange
intPlatform dependent. 32 bits in 32 bit systems and 64 bit in 64 bit systems-2147483648 to 2147483647 in 32 bit platform
-9223372036854775808 to 9223372036854775807 in 64 bit platform
int88 bits/1 byte-128 to 127
int1616 bits/2 byte-32768 to 32767
int32 (rune)32 bits/4 byte-2147483648 to 2147483647
int6464 bits/8 byte-9223372036854775808 to 9223372036854775807

Unsigned integer types can store only positive numeric values.The following table lists unsigned integer types:

TypeSizeRange
UintPlatform dependent: 32 bits in 32 bit platform and 64 bit in 64 bit platform0 to 4294967295 in 32 bit platform
0 to 18446744073709551615 in 64 bit platform
uint8 (byte)8 bits/1 byte0 to 255
uint1616 bits/2 byte0 to 65535
uint3232 bits/4 byte0 to 4294967295
uInt6464 bits/8 byte0 to 18446744073709551615
UintptrPlatform dependentPlatform dependent

Note: If you do not specify a type for numeric values, the defulat type will be int. The uintptr is an unsigned integer type that can hold a pointer address.

Float Types

The float types store positive and negative numeric values with a decimal point, e.g. 15.5, -20.55, or 4578.5568. The following table lists floating point types:

TypeSizeRange
Float3232 bits or 4 bytes-3.4e+38 to 3.4e+38.
Float6464 bits/8 bytes-1.7e+308 to +1.7e+308.

The following table lists complex numeric types:

TypeSizeExample
Complex64Consists of float32 as real and imaginary parts5 + 6i
Complex128Consists of float64 as real and imaginary parts-10.4 +23.41i

Let's see how to declare variables of different data types in the next page.