Arrays
ââââââ¬âââââ¬âââââ¬âââââ¬ââââââ¬ââââââ
| 2 | 3 | 5 | 7 | 11 | 13 |
ââââââ´âââââ´âââââ´âââââ´ââââââ´ââââââ
0 1 2 3 4 5
primes := [...]int{2, 3, 5, 7, 11, 13}
fmt.Println(len(primes)) // => 6
// Outputs: [2 3 5 7 11 13]
fmt.Println(primes)
// Same as [:3], Outputs: [2 3 5]
fmt.Println(primes[0:3])
var a [2]string
a[0] = "Hello"
a[1] = "World"
fmt.Println(a[0], a[1]) //=> Hello World
fmt.Println(a) // => [Hello World]
#2d array
var twoDimension [2][3]int
for i := 0; i < 2; i++ {
for j := 0; j < 3; j++ {
twoDimension[i][j] = i + j
}
}
// => 2d: [[0 1 2] [1 2 3]]
fmt.Println("2d: ", twoDimension)
Comments