OneCompiler

Data Types

As the name suggests, data-type specifies the type of the data present in the variable. Variables must be declared with a data-type.

1. Numeric Data types

Integer Data types

Data typeDescriptionSizeRange
uint88-bit unsigned integer1 byte0 to 255
int88-bit signed integer1 byte-128 to 127
int1616-bit signed integer2 bytes-32768 to 32767
unit1616-bit unsigned integer2 bytes0 to 65,535
int3232-bit signed integer4 bytes-2,147,483,648 to 2,147,483,647
uint3232-bit unsigned integer4 bytes0 to 4,294,967,295
int6464-bit signed integer8 bytes-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
uint6464-bit unsigned integer8 bytes0 to 18,446,744,073,709,551,615

Float Data types

Data typeDescription
float3232-bit signed floating point number
float6464-bit signed floating point number
complex32Number has float32 real and imaginary parts
complex64Number has float32 real and imaginary parts

2. Boolean Data types

Data typeDescriptionSizeRange
boolStores either true or false1 byteTrue or false

3. String Data types

Data typeDescription
stringsequence of characters

Example

package main

import (
	"fmt"
	"math/cmplx"
)

var (
	integer uint32 =  1<<32 - 1
	flt float64 = 3.14
    complexNum complex128 = cmplx.Sqrt(8 - 6i)
    str string = "Hello World"
    boolean bool = true
)

func main() {
	fmt.Printf("Value: %v is of Type: %T\n", integer, integer)
	fmt.Printf("Value: %v is of Type: %T\n", flt, flt)
	fmt.Printf("Value: %v is of Type: %T\n", complexNum, complexNum)
	fmt.Printf("Value: %v is of Type: %T\n", str, str)
	fmt.Printf("Value: %v is of Type: %T\n", boolean, boolean)
}

Check result here