feat: init & playaround

This commit is contained in:
2026-03-01 21:03:32 +01:00
commit de9137b84e
10 changed files with 313 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package main
import (
"fmt"
// "slices"
)
func main() {
var s []string
fmt.Println("uninit", s, s == nil, len(s) == 0)
s = make([]string, 3)
fmt.Println("emp:", s, "len:", len(s), "cap:", cap(s))
s[0] = "a"
s[1] = "b"
s[2] = "c"
fmt.Println("set:", s)
fmt.Println("get:", s[2])
s = append(s, "d")
s = append(s, "e", "f")
fmt.Println("apd:", s)
f := make([]int, 3, 10)
fmt.Println("f:", f, "len:", len(f), "cap:", cap(f))
c := make([]string, len(s))
copy(c, s)
fmt.Println("cpy:", c)
l := s[2:5]
fmt.Println("sl1:", l)
// two d slices
twoD := make([][]int, 10)
for i := range len(twoD) {
innerLen := i + 1
twoD[i] = make([]int, innerLen)
for j := range innerLen {
twoD[i][j] = 1 + j
}
}
fmt.Println("2d: ", twoD)
}