Basic Types
Go does have a wide range of built-in types as well as allows the programmer to define custom types. We would discuss these later in depths. Here are some basic types that one should know before proceeding forward
bool // holds boolean values
string // holds string values
int int8 int16 int32 int64 // signed integer values
uint uint8 uint16 uint32 uint64 uintptr // unsigned integer values
byte // same as uint8
rune // alias for int32, represents a Unicode code point
float32 float64
complex64 complex128
Bit size of int, uint, uintptr depends on system architecture. On 32 bit system, they would be assumed to 32 bit wide, while on 64 bit system, they would be 64 bit wide.
Usually using int
should suffice unless we have specific reason to use signed, unsigned or other varying types of integers/floats.
Type Conversions
Go allows type conversion from one type to another via T(v)
where T
is type to cast to v
is value to be typecasted.
In Golang, var of one type can not be assigned value of other type unless converted
var age int = 23
var agef float64 = float64(age)
var ageu uint = uint(agef)
Last updated
Was this helpful?