❮ Arrays
❯
- len
- []
- len
Arrays
An array can hold a series of values. Both the length and the type of the values of an array is fixed at the time we create it.
Unlike in some other languages, you cannot mix different types of values in an array.
The content can be changed.
We can access the individual elements of an array with a post-fix square-bracket indexing.
- Length is part of the type!
- Two arrays with different length are also different types.
examples/array/array.go
package main import ( "fmt" ) func main() { var res = [3]int{7, 5, 9} fmt.Println(res) fmt.Println(res[1]) fmt.Println(len(res)) fmt.Printf("%T\n", res) }
[7 5 9] 5 3 [3]int