Golang Data Types

Last Updated: September 13, 2022

In Go, there are four types of data:

» Basic: Examples include strings, numbers, and Booleans.
» Aggregate: Examples include arrays and structs.
» Reference: Examples include pointers, slices, functions, and channels.

» Interface: An interface is a collection of method signatures.

Type Size(bits) Details
int8 8

Integers from -128 to 127

var b int8 = 100;
int16 16

Integers from -32,768 to 32,767

short s = 20000;
int32 32

Integers from -2,147,483,648 to 2,147,483,647

var b int16 = 1 000 000 000
int64 64

Integers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

var b int64= 3466366466
float 32

Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits

float x= 67.67;
double 64

Stores fractional numbers. Sufficient for storing 15 decimal digits

double num = 2.34 double x= 1.233456
char 16

tores a single character/letter or ASCII values

char a = ‘a';
boolean 1

Stores true or false values

boolean isFound = true;

Complex Numbers in Go

package main

import "fmt"

func main() {
var i complex64 = 1 + 2i
// var i complex64 = complex(1,2)
fmt.Printf("%v,%T\n", i, i)
fmt.Printf("%v,%T\n", real(i), real(i))
fmt.Printf("%v,%T\n", imag(i), imag(i))
}

Data types conversion in Go language

Test