Go

Go - Arrays and Slices

Gagandeep Singh
Arrays Like any other programming language, arrays in Go are used to group elements of same type and has a fixed length together. Whenever an array is declared or initialized the type of array has to be defined. Type of elements and the length are both used to defined the type of the array. For example, the array below can store string values and it’s length is 4, so its type is [4]string.

Structs in Go

Gagandeep Singh
Struct in Go allows to create custom data types. In the example below User is a struct type, it’s defined using the type keyword followed by the struct name and then struct. Struct can have once or more fields in it and fields are defined using name and type. For example: package main import "fmt" func main() { type User struct { firstname, lastname string age int } u1 := User{ firstname: "Gagandeep", lastname: "Singh", age: 32} fmt.