int
float: float32, float64
complex number: complex64, complex128 a := 5 + 6i
byte, short for uint8, meaning it's an interger value of 8 bits and represents one byte i.e number (0 -255). A single byte therefore can represent ASCII characters.
func main() {
var r byte = 'a'
fmt.Printf("Size: %d", unsafe.Sizeof(r)) // 1
fmt.Printf("Type: %s", reflect.TypeOf(r)) // uint8
fmt.Printf("Character: %c", r) // a
s := "abc"
// this will return the decimal value of byte
fmt.Println([]byte(s)) // [97 98 99]
}
rune, an alias for int32, also an interger value and represents a Unicode Code Point.
string, is a read only slice of bytes in golang. Each character in a string will occupy some bytes depending upon encoding used.
// In utf-8 , a/b are encoded using 1 byte while the £ is encoded using two bytes.
s := "ab£"
fmt.Println([]byte(s)) // [48 98 194 163]
fmt.Println(len("ab£")) // 4
for _, c := range s {
fmt.Println(string(c))
}
//a
//b
//£
boolean
Arrays in go are values, fixed-length sequences of the same type. Since arrays are values, when you assign an array to another var, it copies the entire array.
newArray := [n]Type{val1, val2, val3}
Struct is named collection of fields.